明明db.auth
返回1,可是mongo -u admin -p
就是失败,为啥呢?
andyliwr@andyliwrPC:~/文档/xiaodiFTP/nodejs/xiaodiTodoList$ mongo
MongoDB shell version: 2.6.10
connecting to: test
> use admin
switched to db admin
> db.auth("admin", "123456")
1
> db.auth("admin", "1234535")
Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 }
0
> exit
bye
andyliwr@andyliwrPC:~/文档/xiaodiFTP/nodejs/xiaodiTodoList$ mongo -u admin -p
MongoDB shell version: 2.6.10
Enter password:
connecting to: test
2016-07-31T22:41:33.520+0800 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1287
exception: login failed
Your user is in
admin
这个数据库中的,而默认连接的数据库是test
,自然认证会失败,你应该在使用mongo
连接时指定数据库为admin
so that proper authentication can occur:They are all for designated use
admin
这个库中的用户来认证。有困难找文档,或者看一下--help
. The version on my machine is 3.2, which may be slightly different from yours on 2.6.