简体   繁体   中英

Meteor.js + external Mongo. Meteor cannot login into Mongo

I have a meteor.js app + mongo db (2.6) .

I've created a user in mongo like this:

use meteor
db.createUser(
  {
    user: "meteor",
    pwd: "password",
    roles:
    [
      {
        role: "userAdmin",
        db: "meteor"
      }
    ]
  }
)

here is my mongodb.conf :

dbpath=/data/db
logpath=/var/log/mongodb/mongodb.log
logappend=true
port = 27017

when i set auth = true then my meteor app cannot connect to mongo anymore. It says

Exception in callback of async function: MongoError: auth failed

Same error when i try to connect with RoboMongo when auth is true. When auth is false i can connect with RoboMongo. So it's not about Firewall or something.

I don't understand, what I can do to switch on authorization in Mongo, so that it would let me login. Please help.

It depends on how you start Meteor. You need to tell it which Mongo instance to use and also provide proper credentials like this:

export MONGO_URL=mongodb://<username>:<password>@<host>:<port>/<db>

That's the way I've been doing it with my Meteor apps and a dedicated MongoDB and it works nicely. But if RoboMongo is not able to connect, there may be something wrong with the Mongo configuration. You can use this command to enable authentication in your config:

mongod --auth --config /path/to/mongodb.conf

I assume you have an admin user already which was used to create the meteor user, you will run into issues if you start Mongo without authentication, then add a meteor user anonymously and restart with auth=true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM