【问题标题】:Mongoose with Authentication causes timeoutMongoose with Authentication 导致超时
【发布时间】:2016-11-10 06:12:39
【问题描述】:

所以我们遇到了一个有趣的问题。我们想在 MongoDB 层添加身份验证以提高安全性。但是我们没有得到一个好的结果。

预设置

  1. 以 root 身份使用 mongo shell(针对管理表)
  2. 切换到所需的数据库 (applicationdb)
  3. 执行 db.createUser()
  4. 验证用户创建成功

    { "_id" : "applicationdb.appuser", “用户”:“应用用户”, “数据库”:“应用程序数据库”, “角色”:[ { “角色”:“读写”, “数据库”:“应用程序数据库” } ] }

场景 1:

  1. 更改 mongodb.conf,auth=true
  2. 重启 Mongod 服务
  3. 使用以下方式连接猫鼬:

    mongoose.connect('mongodb://appuser:password@xx.xxx.xxx.xxx:27017/applicationdb');

  4. 没有收到连接错误,因此尝试通过 Mongoose 执行 GET 会导致操作超时而没有任何错误(至少我能找到)

场景 2:

  1. 更改 mongodb.conf,auth=false
  2. 重启 Mongod 服务
  3. 使用以下方式连接猫鼬:

    mongoose.connect('mongodb://xx.xxx.xxx.xxx:27017/applicationdb');

  4. 没有收到连接错误,所以尝试通过 Mongoose 执行 GET 并成功返回文档

为什么在 MongoDB 中使用身份验证时,我们会收到此超时并且从未完成请求?

任何帮助都会很棒,我们在这方面不知所措!

【问题讨论】:

  • 能否添加猫鼬连接代码,设置的选项。
  • @virattara,使用的代码在每个场景的第3步下。

标签: node.js mongodb authentication mongoose


【解决方案1】:

您需要使用--auth 选项重新启动mongo 服务,请参阅here

如果它不起作用,请执行以下操作: 尝试使用 keepAlive 设置猫鼬中的服务器选项。请参阅herehere

【讨论】:

  • 非常感谢,--auth 是这样做的选项
猜你喜欢
  • 1970-01-01
  • 2021-12-30
  • 2018-05-16
  • 2016-09-24
  • 2021-10-24
  • 2012-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多