在 Fedora23 上我使用 安装了 MongoDB dnf
。
sudo dnf install -y mongod
sudo systemctl restart mongod
但它不适用于show dbs
$ mongo
MongoDB shell version: 3.0.9
connecting to: test
> show dbs
2016-03-08T14:45:58.188+0530 E QUERY Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
}
at Error (<anonymous>)
at Mongo.getDBs (src/mongo/shell/mongo.js:47:15)
at shellHelper.show (src/mongo/shell/utils.js:630:33)
at shellHelper (src/mongo/shell/utils.js:524:36)
at (shellhelp2):1:1 at src/mongo/shell/mongo.js:47
>
这也不起作用:
> db.createUser({user: "admin", pwd: "password", roles: [{role: "root", db: "admin"}]})
2016-03-08T14:48:34.595+0530 E QUERY Error: couldn't add user: not authorized on test to execute command { createUser: "admin", pwd: "xxx", roles: [ { role: "root", db: "admin" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 30000.0 } }
at Error (<anonymous>)
at DB.createUser (src/mongo/shell/db.js:1101:11)
at (shell):1:4 at src/mongo/shell/db.js:1101
>
参考:https://stackoverflow.com/questions/23943651/mongodb-admin-user-not-authorized
即使sudo mongo
我看到了同样的错误。
我该如何解决?