mongo
db.createCollection('demodb')
create super user
db.createUser(
{
user: "user",
pwd: "password",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
create app user
mongo --port 27017 -u "user" -p "password" --authenticationDatabase "admin"
use demodb
db.createUser(
{
user: "demo",
pwd: "demopwd",
roles: [ { role: "readWrite", db: "demodb" } ]
}
)
exit
mongo -u demo -p demopwd --authenticationDatabase demodb
use demodb
db.getCollection('yourcollection').find()
开启验证
/usr/bin/mongod --auth -f /etc/mongod.conf
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。