mongodb创建root和普通user

1、创建管理员,下面以用户test1为例:

use admin
db.createUser({user: "test1", pwd: "test1", roles: [{role: "root", db: "admin"}]})

2、创建test2db对应的test2用户:

use test2db
db.createUser({user: "test2", pwd: "test2", roles: [{role: "readWrite", db: "test2db" }]})