-
Type: Bug
-
Resolution: Duplicate
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
Empty show more show less
Hey, I have an account on mlab that I've been using for a while with the mongojs package. But recently I decided to switch over to the mongodb package (because it supports promises) and I can't connect to my database for some reason. I'm using the same connection string that worked with mongojs, I also tried to create a new user and connect to it but it doesn't work either
I'm using the following code:
mongo = require('mongodb').MongoClient url = "....." // works with mongojs var userId = "..." // valid id mongo.connect(url) .then(client => { var db = client.db("socialNet2") return db.collection('posts').find(\{authorId: ObjectId(userId)}).toArray() }) .then(posts => { console.log(posts); res.json(posts) }) .catch(err => { console.log(err); res.json(\{error: err}) });
The full error is this:
{ MongoError: not authorized on socialNet2 to execute command \{ find: "posts", filter: { authorId: ObjectId('5b6339307552e73588bdd486') }, returnKey: false, showRecordId: false, $clusterTime: \{ clusterTime: Timestamp(1533635317, 14), signature: { hash: BinData(0, 6E2A8E5890CE0A57D28BDC4C524B8599FF99FBBA), keyId: 6584951172832952321 } }, lsid: \{ id: UUID("eb11f190-d4f4-478d-b5f4-2607dd73b3c3") }, $db: "socialNet2" } at queryCallback (F:\Programming\Node.js\socialNet2\server\node_modules\mongodb-core\lib\cursor.js:247:25) at F:\Programming\Node.js\socialNet2\server\node_modules\mongodb-core\lib\connection\pool.js:531:18 at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) name: 'MongoError', message: 'not authorized on socialNet2 to execute command \{ find: "posts", filter: { authorId: ObjectId(\'5b6339307552e73588bdd486\') }, returnKey: false, showRecordId: false, $clusterTime: \{ clusterTime: Timestamp(1533635317, 14), signature: { hash: BinData(0, 6E2A8E5890CE0A57D28BDC4C524B8599FF99FBBA), keyId: 6584951172832952321 } }, lsid: \{ id: UUID("eb11f190-d4f4-478d-b5f4-2607dd73b3c3") }, $db: "socialNet2" }', operationTime: Timestamp \{ _bsontype: 'Timestamp', low_: 14, high_: 1533635317 }, ok: 0, errmsg: 'not authorized on socialNet2 to execute command \{ find: "posts", filter: { authorId: ObjectId(\'5b6339307552e73588bdd486\') }, returnKey: false, showRecordId: false, $clusterTime: \{ clusterTime: Timestamp(1533635317, 14), signature: { hash: BinData(0, 6E2A8E5890CE0A57D28BDC4C524B8599FF99FBBA), keyId: 6584951172832952321 } }, lsid: \{ id: UUID("eb11f190-d4f4-478d-b5f4-2607dd73b3c3") }, $db: "socialNet2" }', code: 13, codeName: 'Unauthorized', '$clusterTime': \{ clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 14, high_: 1533635317 }, signature: \{ hash: [Object], keyId: [Object] } }, [Symbol(mongoErrorContextSymbol)]: {} }
- duplicates
-
NODE-1635 Setting useNewUrlParser: true in connection causes issue.
- Closed