【问题标题】:Can't connect from mongojs but command line is OK无法从 mongojs 连接,但命令行可以
【发布时间】:2015-12-26 07:05:49
【问题描述】:

我使用 mongojs 将我的 Node.JS 连接到 MongoDB。

当我从 bash 中执行 mongo easymail -u admin -p PWD --authenticationDatabase=admin 时,一切正常。

但是:mongodb://admin:PWD@localhost:27017/easymail?auto_reconnect=true&authSource=admin给我

{ [MongoError: auth failed] name: 'MongoError', message: 'auth failed', ok: 0, errmsg: 'auth failed', code: 18 }

问题出在哪里?

谢谢!

【问题讨论】:

标签: node.js mongodb authentication mongojs


【解决方案1】:

您没有包含整个命令,但看起来这可能是转义的问题。尝试将连接字符串放在双引号中,如下所示:

mongo "mongodb://admin:PWD@localhost:27017/easymail?auto_reconnect=true&authSource=admin"

【讨论】:

  • 你好,我看不到任何双引号......我试过你的命令:Error: More than one ':' detected.
  • 我将您的命令缩小到 mongo localhost:27017/easymail?authSource=admin -u admin -p PWD 以使其正常工作。同样的问题“身份验证失败”。但是当我做mongo localhost:27017/admin -u admin -p PWD 时,一切都很好......
  • 看来 mongoDB 忽略了 shell 或节点的 authSource 参数
猜你喜欢
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 2020-04-27
  • 1970-01-01
  • 1970-01-01
  • 2011-11-28
  • 1970-01-01
  • 2011-05-03
相关资源
最近更新 更多