身思乐,人事爱,稳恒不言败!

mongodb验证权限是否生效

$ mongo
MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.2
> show dbs
2018-02-01T14:39:46.976+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:813:19
shellHelper@src/mongo/shell/utils.js:703:15
@(shellhelp2):1:1
> use admin
switched to db admin
> db.auth('admin', 'mongodb123456')
1
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB

from:https://zhuanlan.zhihu.com/p/33557163