很纳闷,自建mongodb外网访问开起来就中毒了,把库都删掉了。目前只能重新创建库了。
> show dbs
2017-08-17T15:43:01.681+0800 E QUERY [thread1] Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
shellHelper.show@src/mongo/shell/utils.js:761:19
shellHelper@src/mongo/shell/utils.js:651:15
@(shellhelp2):1:1
首先创建用户管理用户
use admin
db.createUser(
{user:'user',
pwd:'passwd',
roles:[
{role:'userAdminAnyDatabase', db:'admin'}
]
})
使用用户管理账户登录认证
use admin
db.auth('user', 'passwd')
建立普通帐号
use lzmh_test
db.createUser(
{
user: "lzmh_test",
pwd: "lzmh_test@2016",
roles: [ { role: "readWrite", db: " lzmh_test " } ]
{
user: "lzmh_test",
pwd: "lzmh_test@2016",
roles: [ { role: "readWrite", db: " lzmh_test " } ]
}
)