mongodb 如何从 Mac OS 终端连接到远程 mongo 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26813912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can I connect to a remote mongo server from Mac OS terminal
提问by jononomo
I would like to drop into the mongo shell in the terminal on my MacBook. However, I'm interested in connecting to a Mongo instance that is running in the cloud (compose.io instance via Heroku addon). I have the name, password, host, port, and database name from the MongoDB URI:
我想进入我 MacBook 终端中的 mongo shell。但是,我有兴趣连接到在云中运行的 Mongo 实例(通过 Heroku 插件的 compose.io 实例)。我有来自 MongoDB URI 的名称、密码、主机、端口和数据库名称:
mongodb://username:[email protected]:10011/my_database
I have installed mongodb on my MacBook using Homebrew not because I want Mongo running on my Mac, but just to get access to the mongo shell program in order to connect to this remote database.
我已经使用 Homebrew 在我的 MacBook 上安装了 mongodb,不是因为我想要在我的 Mac 上运行 Mongo,而是为了访问 mongo shell 程序以连接到这个远程数据库。
However, I can't find the right command to get me the full shell access I would like. Using instructions found here http://docs.mongodb.org/manual/reference/program/mongo/(search for "remote") I am able to get what looks like a connection, but without giving my username or password I am not fully connected. Running db.auth(username, password)
returns 1 (as opposed to "auth fails" when I provide incorrect username and password), but I continue to get an "unauthorized" error message when issuing the show dbs
command.
但是,我找不到正确的命令来获得我想要的完整 shell 访问权限。使用此处找到的说明http://docs.mongodb.org/manual/reference/program/mongo/(搜索“remote”)我能够获得看起来像连接的东西,但没有提供我的用户名或密码我不是完全连接。运行db.auth(username, password)
返回 1(当我提供不正确的用户名和密码时,与“身份验证失败”相反),但在发出show dbs
命令时我继续收到“未经授权”的错误消息。
回答by Ben
You are probably connecting fine but don't have sufficient privileges to run show dbs
.
您可能连接正常,但没有足够的权限运行show dbs
.
You don't need to run the db.auth if you pass the auth in the command line:
如果在命令行中传递 auth,则不需要运行 db.auth:
mongo somewhere.mongolayer.com:10011/my_database -u username -p password
Once you connect are you able to see collections?
连接后是否可以查看收藏?
> show collections
If so all is well and you just don't have admin privileges to the database and can't run the show dbs
如果是这样,一切都很好,您只是没有数据库的管理员权限并且无法运行 show dbs
回答by Amio.io
With Mongo 3.2 and higherjust use your connection string as is:
对于 Mongo 3.2 及更高版本,只需按原样使用您的连接字符串:
mongo mongodb://username:[email protected]:10011/my_database
回答by KayV
Another way to do this is:
另一种方法是:
mongo mongodb://mongoDbIPorDomain:port