Windows MongoDB installed and started User Authentication

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
Windows MongoDB installed and started User Authentication

II. Installation

Windows MongoDB installed and started User Authentication

Windows MongoDB installed and started User Authentication

Note: Select Custom Installation
Windows MongoDB installed and started User Authentication
D: \ Program Files \ MongoDB \ Server \ 4.2 \

D: \ Program Files \ MongoDB \ Server \ 4.2 \ the Data \
D: \ Program Files \ MongoDB \ Server \ 4.2 \ log \
Windows MongoDB installed and started User Authentication
Compass is mongodb client software installed temporarily
Windows MongoDB installed and started User Authentication

It allows programs to install software on this computer

III. Start Run as Administrator cmd
NET Start MongoDB
Windows MongoDB installed and started User Authentication
computer Right Management can also manage the service (Off, On)
Windows MongoDB installed and started User Authentication

Install Client Tools Navicat121_Mongodb_x64 and connection (no certification)
Windows MongoDB installed and started User Authentication

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;
Windows MongoDB installed and started User Authentication
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
Windows MongoDB installed and started User Authentication

VII. Mongodb restart
the Run as Administrator cmd
NET Start mongodb
NET STOP mongodb

Eight. Connecting
Windows MongoDB installed and started User Authentication
Windows MongoDB installed and started User Authentication
cooper user login authentication authority
use the testdb;
db.user.insert ({_ ID: 2, name: "SAM", Age: 32})
db.user.find ()
Windows MongoDB installed and started User Authentication
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

Guess you like

Origin blog.51cto.com/dg123/2477140