连接在远程计算机上运行的mongodb

时间:2020-04-03 13:03:28

标签: mongodb mongodb-query

MongoDB在可通过我的机器访问的远程机器上运行。我尝试在我的机器上给出命令

telnet“远程机器ip” 27017

它可以连接。

但是如果我通过发出此命令连接客户端

mongo“ machine ip”-端口27017 -u sample -p sample --authenticationDatabase admin

我收到“身份验证失败”错误。

但是使用该用户名和密码,我可以在远程计算机中进行连接。同样在mongod.cfg文件中,将属性“ bindIpAll”设置为true。

我在这里有什么想念的吗?

1 个答案:

答案 0 :(得分:0)

当您收到“身份验证失败”错误时,说明您已经连接了MongoDB。

您必须将数据库地址放在末尾或指定为选项,即

mongo --port 27017 -u sample -p sample --authenticationDatabase admin "machine ip"

mongo --host "machine ip" --port 27017 -u sample -p sample --authenticationDatabase admin
c:\>mongo -h
MongoDB shell version v4.2.0
usage: mongo [options] [db address] [file names (ending in .js)]
db address can be:
  foo                   foo database on local machine
  192.168.0.5/foo       foo database on 192.168.0.5 machine
  192.168.0.5:9999/foo  foo database on 192.168.0.5 machine on port 9999
  mongodb://192.168.0.5:9999/foo  connection string URI can also be used