1

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.

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

in the script for the actual node app I am using the export as you mentioned. If I also have to pass username and password in the Meteor app, wouldn't that negate some security?
Also, when I use the mongocli and authenticate to "bob" using use admin db.auth('bob', '12345') I can fully manipulate the myDB (insert, query, etc.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.