1、Start a mongod with the parameter--auth
2、Connect to mongod through thelocalhost exception
mongo 127.0.0.1:10000
3、create the system useradministrator named root with the only rootrole(root是最高权限。)。
test@lsl-PC> use admin
switched to db admin
admin@lsl-PC> db.createUser(
... {
... user:"root",
... pwd:"123",
... roles: [ { role: "root", db: "admin" } ]
... }
... )
在admin库中创建的具有root角色的用户是超级用户,可以执行任何操作。为方便管理,也为了安全,应该建立这样一个用户并妥善保管其密码。
注意:在v3.0中,一旦上述用户创建,则当前的localconnection马上失去任何操作权限;而在之前的版本中,当前的connection还具有超级用户的权限。