0
我已经创建了一个干净的数据库上的新用户,但无法连接它。但是,我可以连接没有凭据。创建一个用户,但不能连接它
PS C:\Program Files\MongoDB\Server\3.0\bin> .\mongo.exe localhost/test
MongoDB shell version: 3.0.11
connecting to: localhost/test
> var me = { user: 'dave', pwd: 'password', roles: [ 'userAdminAnyDatabase'] }
> use admin
switched to db admin
> db.createUser(me)
Successfully added user: { "user" : "dave", "roles" : [ "userAdminAnyDatabase" ] }
> ^C
bye
PS C:\Program Files\MongoDB\Server\3.0\bin> .\mongo.exe -u dave -p password
MongoDB shell version: 3.0.11
connecting to: test
2016-04-27T15:40:38.185+0100 E QUERY Error: 18 Authentication failed.
at DB._authOrThrow (src/mongo/shell/db.js:1271:32)
at (auth):6:8
at (auth):7:2 at src/mongo/shell/db.js:1271
exception: login failed
我相信你正在连接到测试数据库。但用户是在管理数据库中创建的。 尝试在测试中创建用户。 '使用测试'。或者在登录时指定要连接的方案。 –
就是这样。谢谢。如果你愿意,你可以把它作为答案。 – BanksySan
完美!很高兴它的工作 –