Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loopback MongoError: not authorized for query on heroku_xxxx.role

I'm using Loopback for my server with the following setup:

"loopback": "^2.36.0",
"loopback-boot": "^2.23.0",
"loopback-component-explorer": "^2.4.0",
"loopback-component-storage": "^1.9.1",
"loopback-connector-mongodb": "^1.17.0",
"loopback-datasource-juggler": "^2.53.0",

It's connecting to a mongoDB that's on mlab.com

My main query includes a model and it's dependencies, ex:

GET /api/course/1234
PARAMS filter = {
     include: [
          {relation:'students'},
          {relation:'documents'},
          {relation:'modules'}
     ]
}

99.9% of the time, it works perfectly. But when I start having more activity on the platform, I start getting this error before the server starts crashing. Here's the error:

MongoError: not authorized for query on db.student
at Function.MongoError.create (/app/node_modules/mongodb-core/lib/error.js:31:11)
at queryCallback (/app/node_modules/mongodb-core/lib/cursor.js:182:34)
at /app/node_modules/continuation-local-storage/context.js:76:17
at bound (domain.js:287:14)
at runBound (domain.js:300:12)
at Callbacks.emit (/app/node_modules/mongodb-core/lib/topologies/server.js:119:3)
at null.messageHandler (/app/node_modules/mongodb-core/lib/topologies/server.js:397:23)
at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:302:22)

Sometimes it's on db.students, sometimes it's on db.documents ... seems random and I have no idea how to fix it.

To connect to the DB, I use the URI provided by mlab. Which looks like this:

mongodb://<dbuser>:<dbpassword>@<dbpath>/<dbname>

With and without ?&authMode=scram-sha1&rm.tcpNoDelay=true, but still getting errors with.

Any ideas what's happening and how to fix this?

__ Edit: I've tried a couple of different versions with no luck. Latest is:

"loopback": "^2.22.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^2.4.0",
"loopback-component-storage": "^1.9.1",
"loopback-connector-mongodb": "^1.17.0",
"loopback-datasource-juggler": "^2.39.0",

__ Edit: I found this post on Github: https://github.com/strongloop/loopback-connector-mongodb/issues/251 which seems to be the same error, I followed what the others said solved their problems by changing the [email protected] but still no luck...

like image 603
denislexic Avatar asked Nov 02 '16 00:11

denislexic


1 Answers

The solution was to update Loopback to the latest version. The Loopback library includes the MongoDB Node driver as a dependency and uses the driver to connect to a MongoDB database.

Previous versions of the MongoDB Node driver have known connection/authentication issues. By updating to the latest Loopback version, a more recent version of the Node driver was installed.

like image 154
Chris Chang Avatar answered Sep 23 '22 00:09

Chris Chang