Tester v6 engine
Tester v6 engine

Reputation: 29

TypeError: Cannot read property 'dbName' of null

I've tried to connect my Loopback application with MongoDb Atlas, but I'm having an error "TypeError: Cannot read property 'dbName' of null".

Below is what I've tried:

  1. run lb data source
  2. Fill all the required info
  3. Generated this javascript object:
{
  "db": {
    "name": "db",
    "connector": "mongodb"
  },
  "mongodb": {
    "host": "",
    "port": 0,
    "url": "mongodb+srv://USER:[email protected]/test?retryWrites=true&w=majority",
    "database": "DATABASENAME",
    "password": "PASSWORD",
    "name": "mongodb",
    "user": "dbAdmin",
    "useNewUrlParser": true,
    "connector": "mongodb"
  }
}
  1. On every attempt to run "node ." , getting TypeError: Cannot read property 'dbName' of null.

  2. I've added my IP in the whitelisted IPs (MongoDB atlas)

  3. Below is my model.config.json

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins"
    ]
  },
  "User": {
    "dataSource": "mongodb"
  },
  "AccessToken": {
    "dataSource": "mongodb",
    "public": false
  },
  "ACL": {
    "dataSource": "mongodb",
    "public": false
  },
  "RoleMapping": {
    "dataSource": "mongodb",
    "public": false,
    "options": {
      "strictObjectIDCoercion": true
    }
  },
  "Role": {
    "dataSource": "mongodb",
    "public": false
  }
}

PS: I'm using loopback 3x

Upvotes: 0

Views: 834

Answers (2)

Bilal Khursheed
Bilal Khursheed

Reputation: 836

Don't put special character in your password, if you are using old mongodb

Upvotes: 0

Tester v6 engine
Tester v6 engine

Reputation: 29

Figured out that setting the property "useNewUrlParser": true to false solved my issue. Still don't know why this was the root cause.

Upvotes: 1

Related Questions