【问题标题】:Connect the mongodb running on remote machine连接远程机器上运行的mongodb
【发布时间】:2020-04-03 13:03:28
【问题描述】:

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

telnet "远程机器ip" 27017

可以连接。

但是如果我通过给出这个命令在客户端连接

mongo "机器 ip" --port 27017 -u sample -p sample --authenticationDatabase admin

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

但是使用该用户名和密码,我可以连接到远程机器。也在 mongod.cfg 文件中启用了属性“bindIpAll”为真。

这里有什么我遗漏的地方吗?

【问题讨论】:

    标签: mongodb mongodb-query


    【解决方案1】:

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

    你必须把 db address 放在最后或指定为选项,即

    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
    

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 2019-02-15
      • 1970-01-01
      • 2016-08-02
      • 2015-12-05
      • 1970-01-01
      • 2017-06-14
      • 2013-07-25
      • 1970-01-01
      相关资源
      最近更新 更多