首页 文章

如何从Mac OS终端连接到远程mongo服务器

提问于
浏览
83

我想放入MacBook终端的mongo shell . 但是,我有兴趣连接到在 Cloud 中运行的Mongo实例(通过Heroku插件进行compose.io实例) . 我有MongoDB URI中的名称,密码,主机,端口和数据库名称:

mongodb://username:password@somewhere.mongolayer.com:10011/my_database

我使用Homebrew在我的MacBook上安装了mongodb并不是因为我想在我的Mac上运行Mongo,而只是为了连接到这个远程数据库而访问mongo shell程序 .

但是,我找不到正确的命令来获取我想要的完整shell访问权限 . 使用此处找到的说明http://docs.mongodb.org/manual/reference/program/mongo/(搜索"remote")我能够获得看起来像连接的内容,但是没有提供我的用户名或密码,我没有完全连接 . 运行 db.auth(username, password) 返回1(而不是"auth fails",当我提供错误的用户名和密码时),但在发出 show dbs 命令时,我仍然收到"unauthorized"错误消息 .

2 回答

  • 39

    使用Mongo 3.2 and higher只需使用您的连接字符串:

    mongo mongodb://username:password@somewhere.mongolayer.com:10011/my_database
    
  • 147

    您可能正常连接但没有足够的权限来运行 show dbs .

    如果在命令行中传递auth,则无需运行db.auth:

    mongo somewhere.mongolayer.com:10011/my_database -u username -p password
    

    连接后你能看到收藏吗?

    > show collections
    

    如果是这样一切都很顺利,你只需要't have admin privileges to the database and can' t运行 show dbs

相关问题