创建管理员
Start MongoDB without access control.
先启动MongoDB服务:
D:\MongoDB\bin>net start MongoDB
或
mongod –port 27017 –dbpath …/data
Connect to the instance.然后连接实例:
D:\MongoDB\bin>mongo
Create the user administrator (in the admin authentication database).
> use admin
switched to db admin
> db.createUser(
{
user:"admin",
pwd:"password",
roles: [ { role:"userAdminAnyDatabase", db:"admin" } ]
}
)
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
Re-start the MongoDB instance with access control.
D:\MongoDB\bin>mo