问题描述
我想插入MacBook终端中的mongo外壳.但是,我有兴趣连接到在云中运行的Mongo实例(通过Heroku插件的comppose.io实例).我有来自MongoDB URI的名称,密码,主机,端口和数据库名称:
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:
mongodb://username:[email protected]:10011/my_database
我使用Homebrew在MacBook上安装了mongodb并不是因为我希望Mongo在我的Mac上运行,而是为了访问mongo shell程序以连接到此远程数据库.
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.
但是,我找不到正确的命令来获得我想要的完整shell访问权限.使用此处的说明 http://docs.mongodb.org/manual/reference/program/mongo/(搜索远程"),我可以得到看起来像连接的东西,但是没有提供我的用户名或密码,我没有完全连接.运行db.auth(username, password)
返回1(与当我提供不正确的用户名和密码时身份验证失败"相对),但是在发出show dbs
命令时,我继续收到未授权"错误消息.
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.
推荐答案
您可能连接良好,但没有足够的权限来运行show dbs
.
You are probably connecting fine but don't have sufficient privileges to run show dbs
.
如果在命令行中通过auth,则无需运行db.auth:
You don't need to run the db.auth if you pass the auth in the command line:
mongo somewhere.mongolayer.com:10011/my_database -u username -p password
连接后,您是否可以看到收藏夹?
Once you connect are you able to see collections?
> show collections
如果一切正常,您就没有数据库管理员权限,并且无法运行show dbs
If so all is well and you just don't have admin privileges to the database and can't run the show dbs
这篇关于如何从Mac OS终端连接到远程mongo服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!