4

我正在尝试从 MongoLab 开始。使用 mongo shell 似乎我无法对我创建的任何数据库进行身份验证,即使使用全新的帐户和数据库也是如此。

我使用与我的 DB 用户相同的用户名和密码创建了 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 

是否有任何额外的端口必须在我的末端打开?

任何人都可以帮忙吗?

谢谢!

达伦

4

1 回答 1

9

好的!我修好了它。

由于某种原因 -u 和 -p 对我不起作用,而且似乎调用 db.auth() 必须在连接后作为 shell 中的第一个命令调用。

此外,对于 pymongo,似乎从服务器字符串解析的用户名/密码不起作用,而是我不得不调用 db.authenticate(user, password)。

于 2013-04-27T17:05:49.960 回答