MAC環境語法:
use admin
db.createUser(
{
user: "dbroot",
pwd: "1111112",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
use m1688
db.createUser(
{
user: "testfree66",
pwd: "1111112",
roles: [
{ role: "readWrite", db: "m1688" },
]
}
)
Linux環境語法:
use admin
db.addUser({
user : 'dbroot',
pwd : '1111112',
roles : [
'clusterAdmin',
'dbAdminAnyDatabase',
'userAdminAnyDatabase',
'readWriteAnyDatabase'
]
})
db.auth('dbroot', '1111112')
use m1688
db.addUser(
{
user: "testfree66",
pwd: "1111112",
roles: [
'readWrite'
]
}
)
db.auth('testfree66', '1111112')
啟動mongo服務:
./mongod --auth --dbpath data/m2 --logpath log/m2.log
進入mongo後臺
mongo --username testfree66 --password 1111112 m1688