Windows MongoDB installation and user authentication open
a. Download the installation package mongodb-win32-x86_64-2012plus-v4.2- latest-signed.msi
the group has installed packages and configuration files, any questions please share
II. Installation
Note: Select Custom Installation
D: \ Program Files \ MongoDB \ Server \ 4.2 \
D: \ Program Files \ MongoDB \ Server \ 4.2 \ the Data \
D: \ Program Files \ MongoDB \ Server \ 4.2 \ log \
Compass is mongodb client software installed temporarily
It allows programs to install software on this computer
III. Start Run as Administrator cmd
NET Start MongoDB
computer Right Management can also manage the service (Off, On)
Install Client Tools Navicat121_Mongodb_x64 and connection (no certification)
Four add user
connection performed mongo
use ADMIN;
4.1 hypervisor creates user
db.createUser ({
User: 'the root',
pwd: '123456',
Roles: [{Role: 'the root', DB: 'ADMIN'}]
})
to view the user users Show;
4.2 library creation read the testdb user, onlinedb cooper user to create read-only library
i.e. cooper can read and write testdb, only read data onlinedb
use ADMIN
db.createUser ({
user: 'cooper',
pwd : '123456',
Roles: [{Role: 'readWrite', DB: 'the testdb'}, {Role: 'Read', DB: 'onlinedb'}]
})
root is the highest authority can manage all database
use the testdb;
db.user.insert (ID {_:. 1, name: "Cooper", Age: 12 is})
db.user.find ()
use onlinedb;
db.stu.insert ({ the _id:. 1, name: "Coco", Age: 22 is})
db.stu.find ()
Five modify the configuration file to add authentication "D: \ Program Files \ MongoDB \ Server \ 4.2 \ bin \ mongod.cfg"
file to add, and then save the
Security:
the Authorization: "Enabled"
. Six to restart the service 1. net stop mongodb 2. net start mongodb
VII. Mongodb restart
the Run as Administrator cmd
NET Start mongodb
NET STOP mongodb
Eight. Connecting
cooper user login authentication authority
use the testdb;
db.user.insert ({_ ID: 2, name: "SAM", Age: 32})
db.user.find ()
use onlinedb;
db.stu.insert ({_ ID: 2, name: "cici", Age: 23 is})
db.stu.find ()
Cooper onlinedb user database read-only, can not be modified
db.stu.insert ({_ id: 2, name: "cici", age: 23 })
[Error] not authorized on onlinedb to execute command { insert: "stu", ordered: true, $db: "onlinedb", lsid: { id: UUID("e4bdfbd1-c3ca-4c2a-8fa4-476580aec004") } }
X. summary and then turn create user authentication