剛在redhat下安裝好mongodb但是卻完全無法使用指令
刚安装好mongodb,主要是在晚上找的安装教程即设置,通过指令却无法进行操作,只能use user。晕~网上找的其他方法也不适用。
可能是我的用户没有授权?
但是我超级用户都还没创建怎么授权呢?
MongoDB shell version v3.6.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server versio: 3.6.0
>use admin
switched to db admin
> db.createUser({
... user: "username",
... pwd: "password",
... roles: ["readWrite", "dbAdmin", "dbOwner"]
... });
2019-03-19T09:19:55.749+0800 E QUERY [thread1] Error: couldn't add user: not authorized on admin to execute command { createUser: "username", pwd: "xxx", roles: [ "readWrite", "dbAdmin", "dbOwner" ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 600000.0 }, $db: "admin" } :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1
> show users
2019-03-19T09:14:15.358+0800 E QUERY [thread1] Error: not authorized on admin to execute command { usersInfo: 1.0, $db: "admin" } :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.getUsers@src/mongo/shell/db.js:1686:1
shellHelper.show@src/mongo/shell/utils.js:793:9
shellHelper@src/mongo/shell/utils.js:700:15
@(shellhelp2):1:1
>db.system.users.find()
Error: error: {
"ok" : 0,
"errmsg" : "not authorized on test to execute command { find: \"system.users\", filter: {}, $db: \"test\" }",
"code" : 13,
"codeName" : "Unauthorized"
}
> show dbs
2019-03-19T09:17:42.938+0800 E QUERY [thread1] Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0, $db: \"admin\" }",
"code" : 13,
"codeName" : "Unauthorized"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:65:1
shellHelper.show@src/mongo/shell/utils.js:810:19
shellHelper@src/mongo/shell/utils.js:700:15
@(shellhelp2):1:1