简体   繁体   English

Meteor.js +外部Mongo。 流星无法登录Mongo

[英]Meteor.js + external Mongo. Meteor cannot login into Mongo

I have a meteor.js app + mongo db (2.6) . 我有一个meteor.js应用程序+ mongo db (2.6)

I've created a user in mongo like this: 我在mongo中创建了这样的用户:

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

here is my mongodb.conf : 这是我的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. 当我设置auth = true我的流星应用程序将无法再连接到mongo。 It says 它说

Exception in callback of async function: MongoError: auth failed

Same error when i try to connect with RoboMongo when auth is true. 当身份验证为true时,我尝试与RoboMongo连接时出现相同的错误。 When auth is false i can connect with RoboMongo. 当auth为false时,我可以与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. 我不明白,我该怎么做才能在Mongo中打开授权,以便它可以登录。 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: 您需要告诉它要使用哪个Mongo实例,并提供适当的凭据,如下所示:

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. 这就是我一直在使用Meteor应用程序和专用的MongoDB进行操作的方式,并且效果很好。 But if RoboMongo is not able to connect, there may be something wrong with the Mongo configuration. 但是,如果RoboMongo无法连接,则Mongo配置可能存在问题。 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. 我假设您已经有一个用于创建流星用户的管理员用户,如果您在不进行身份验证的情况下启动Mongo,然后匿名添加流星用户并使用auth = true重新启动,则会遇到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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