wanderingAscot
wanderingAscot

Reputation: 36

Meteor: MongoError: not authorized for query on db.collection when using authentication

I followed meteor/mongodb: Use different DB for authentication & read/write to a T and am receiving the error when trying to query the db:

Exception while invoking method 'myMethod' MongoError: not authorized for query on myDB.bobRocks

I setup the user in Mongo using:

use admin
db.createUser(
    {
    user: 'bob',
    pwd: '12345',
    roles: [
        { role: 'readWrite', db: 'myDB'},
    ]
    }
)

My Database call is:

var myDB = new MongoInternals.RemoteCollectionDriver("mongodb://10.10.10.100:27017/myDB");
BobRocks = new Mongo.Collection('bobRocks', { _driver: myDB })

Finally I'm using:

MONGO_URL=mongodb://bob:[email protected]:27017/admin meteor run

What am I missing? I would assume the authentication would follow the MONGO_URL declaration but it doesn't appear to.

Upvotes: 1

Views: 808

Answers (1)

Pankaj Jatav
Pankaj Jatav

Reputation: 2184

If you are using linux then you have to export the mongourl like then meteor run like this.

export MONGO_URL=mongodb://bob:[email protected]:27017/admin meteor run

Or if you are using windows then you have to set the mongourl then meteor run.

SET MONGO_URL=mongodb://bob:[email protected]:27017/admin meteor run

Please try to connect using mongo cli first.

You also didn't pass username and password here

var myDB = new MongoInternals.RemoteCollectionDriver("mongodb://10.10.10.100:27017/myDB");

You can pass username and password here like you pass in mongo url like this.

var myDB = new MongoInternals.RemoteCollectionDriver("mongodb://bob:[email protected]:27017/myDB");

And please make sure myDB is exist on remote server.

Upvotes: 0

Related Questions