The current environment win7
1. Prepare
Download mongodb-win32-x86_64-2012plus-4.2.0.zip https://www.mongodb.com/download-center/community
Decompression
Set Environment Variables
PATH=D:\mongodb\bin;%PATH%
2. Start mongo
mongod --dbpath=D:/Mongodata
3. Add users
The client mongo
mongo
(1) Add Administrator
db.createUser({user:"root",pwd:"root",roles:["userAdminAnyDatabase"]})
log in
db.auth("root","root")
(2) Add New Database User
db.createUser({user:"baby",pwd:"123456",roles:["readWrite"]})
(3) View all accounts
db.system.users.find().pretty()
Prior authorization
(4) view account under the current library
show users
(5) forget superuser
Add a profile mongodb.conf
systemLog: destination: file path: d:/Mongodata/log/mongod.log storage: dbPath: d:/Mongodata security: authorization: enabled
start up
mongod --config "D:/mongodb/bin/mongodb.conf"
Modify the configuration file, authorization comments restart mongo, enter the terminal to see the user
systemLog: destination: file path: d:/Mongodata/log/mongod.log storage: dbPath: d:/Mongodata
Change the administrator password
db.changeUserPassword("root","123456")
or
db.updateUser("root",{pwd:"123456"})
(6) Delete User
db.dropUser("baby")
Supplementary Role Description:
Read: allows the user to specify the database to read
readWrite: allows the user to specify the database to read and write
dbAdmin: allows users to perform the specified database management functions, such as indexing to create, delete, view statistics or access system.profile
userAdmin: allowing a user to write to system.users, you can find specify the database to create, delete, and manage users
clusterAdmin: admin only available in the database, the user gives all privileges fragmentation and replication sets associated function.
readAnyDatabase: admin is only available in the database, giving users read access to all databases
readWriteAnyDatabase: only available in the database admin, read and write access gives the user all databases
userAdminAnyDatabase: admin is only available in the database, the user gives permission to all databases userAdmin
dbAdminAnyDatabase: admin is only available in the database, the user gives permission dbAdmin all databases.
root: admin is only available in the database. Super accounts, super powers