我正在尝试使用MongoLab。使用mongo shell似乎无法授权我创建的任何数据库,即使使用全新的帐户和数据库。
我使用与我的数据库用户相同的用户名和密码创建了MongoLab用户,因此我确信没有用户名/密码错误。
# connect to mongod v2.4.3 using 2.4.3 client:
#
imac ~/Desktop/mongodb-osx-x86_64-2.4.3/bin$ ./mongo ds059557.mongolab.com:59557/cachv -u redacted -p redacted
MongoDB shell version: 2.4.3
connecting to: ds059557.mongolab.com:59557/cachv
> use mydb
switched to db mydb
> db.things.insert({f:1})
not authorized for insert on mydb.things
或
# connect to mongod v2.2.4-rc0 using 2.4.3 client:
#
imac ~/Desktop/mongodb-osx-x86_64-2.4.3/bin$ ./mongo dbh83.mongolab.com:27837/cachv2 -u redacted -p redacted
MongoDB shell version: 2.4.3
connecting to: dbh83.mongolab.com:27837/cachv2
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Error while trying to show server startup warnings: need to login
> use mydb
switched to db mydb
> db.things.insert({f:1})
Sat Apr 27 05:46:32.456 JavaScript execution failed: getlasterror failed: { "errmsg" : "need to login", "ok" : 0 } at src/mongo/shell/db.js:L698
> db.auth('redacted','redacted')
Error: 18 { errmsg: "auth fails", ok: 0.0 }
0
接下来的第二次尝试:
imac ~/Desktop/mongodb-osx-x86_64-2.4.3/bin$ ./mongo dbh83.mongolab.com:27837/cachv2 -u redacted -p redacted
MongoDB shell version: 2.4.3
connecting to: dbh83.mongolab.com:27837/cachv2
Error while trying to show server startup warnings: need to login
最后,我下载了旧的2.2.4客户端,但仍然没有运气:
# connect to mongod v2.2.4-rc0 using 2.2.4 client:
#
mac ~/Desktop/mongodb-osx-x86_64-2.2.4/bin$ ./mongo dbh83.mongolab.com:27837/cachv2 -u redacted -p redacted
MongoDB shell version: 2.2.4
connecting to: dbh83.mongolab.com:27837/cachv2
> use mydb
switched to db mydb
> db.things.insert({'g':1})
Sat Apr 27 06:00:30 uncaught exception: getlasterror failed: { "errmsg" : "need to login", "ok" : 0 }
> db.auth('redacted','redacted')
Error: { errmsg: "auth fails", ok: 0.0 }
0
> db.things.insert({'g':1})
Sat Apr 27 06:00:47 uncaught exception: getlasterror failed: { "errmsg" : "need to login", "ok" : 0
我的末尾是否还有其他端口需要打开?
有人可以帮忙吗?
谢谢!
的Darren
答案 0 :(得分:9)
确定!我修好了。
出于某种原因-u和-p对我不起作用,而且似乎必须调用db.auth()作为 第一个 命令在连接后的shell中。
此外,对于pymongo,似乎从服务器字符串解析的用户名/密码不起作用,而是我不得不调用db.authenticate(用户,密码)。