# mongod.conf# for documentation of all options, see:# http://docs.mongodb.org/manual/reference/configuration-options/# Where and how to store data.storage:
dbPath: /var/lib/mongodb
journal:
enabled: true# engine:# wiredTiger:# where to write logging data.systemLog:
destination: file
logAppend: true path: /var/log/mongodb/mongod.log
# network interfacesnet:
port: 10095 bindIp: 0.0.0.0
# how the process runsprocessManagement:
timeZoneInfo: /usr/share/zoneinfo
# 登录是否需要密码#security:# authorization: enabled#operationProfiling:#replication:#sharding:## Enterprise-Only Options:
Mongodb添加用户
(1)连接Mongodb
1
mongo mongodb://127.0.0.1:10095
(2)创建普通用户
1
2
3
4
5
6
7
8
use Production
db.createUser({ user: "production",
pwd: "production@123", // passwordPrompt() Or "<cleartext password>" roles: ["readWrite", "dbAdmin"]})
(3)创建超级用户
1
2
3
4
5
6
7
8
use admin
db.createUser({ user: "mongoAdmin",
pwd: passwordPrompt(), // passwordPrompt() Or "<cleartext password>" roles: ["readWriteAnyDatabase", "userAdminAnyDatabase", "dbAdminAnyDatabase"]})
(4)登录
1
db.auth("production")
Mongodb更新用户权限
(1)连接Mongodb
1
mongo mongodb://127.0.0.1:10095
(2)更新用户权限
1
2
3
4
use Production
# 更新用户权限db.updateUser("production",{roles : [{"role" : "readWriteAnyDatabase","db" : "Stock"},{"role" : "dbAdminAnyDatabase","db" : "Stock"}]})readWriteAnyDatabase