Installation Services Mongod--install--servicename mongodb--storageengine=mmapv1--dbpath i:\mongodb\data--journal--logpath i:\ Mongodb\log\log.txt
Installation Service error with secure authentication Mongod--install--servicename mongodb--port 27017--storageengine=mmapv1--dbpath i:\mongodb\data-- Directoryperdb--journal--logpath i:\mongodb\log\log.txt--logappend--auth wrong
Correct--authmongod--install--servicename mongodb--port 27017--storageengine=mmapv1--dbpath i:\mongodb\data--journal-- LogPath i:\mongodb\log\log.txt--logappend--auth to Mongod--reinstall--servicename mongodb--port 27017--storageengine =mmapv1--dbpath i:\mongodb\data--journal--logpath i:\mongodb\log\log.txt--logappend--auth
Mongod--install--servicename mongodb--port 27017--storageengine=mmapv1--dbpath c:\mongodb\data--journal--logpath C : \mongodb\log\log.txt--logappend--authnet Stop MongoDB
Uninstall Service Mongod--remove--servicename MongoDB
Mongo
>use admin;db.adduser (' admin ', ' 123 '); Repeal
First login, build Super admin >use admin;>db.createuser ({User: ' admin ', pwd: ' 123 ', roles:[' root '});
Exit Client
Oracle 12c 64
Re-login Mongouse admin;db.auth (' admin ', ' 123 '); Verify that you can do anything by
Super Admin directly login server MONGO--host localhost--port 27017--username admin--password 123--authenticationdatabase Admin
Streamlined login I:\mongodb\bin>mongo localhost:27017/admin-u admin-p 123
Use Admin;db.dropuser (' admin ');
Modify the Super Administrator password use admin;db.updateuser (' admin ', {pwd: ' admin '});
Establish a database administrator hndb;
Create a read-only account use Hndb;>db.createuser ({User: ' AA ', pwd: ' AA ', roles:[' read '});
Establish database administrator use Hndb;db.createuser ({User: ' cc ', pwd: ' CC ', roles:[' ReadWrite ')});
Definition: Create a database new user with the Db.createuser () method and return a user repeat error if the user exists. Syntax: Db.createuser (user, Writeconcern) User This document creates authentication and access information about the user, and Writeconcern This document describes a successful report that ensures that MongoDB provides write operations.
· The user document defines the following forms of the users: {User: "<name>", pwd: "<cleartext password>", CustomData: {<any information>}, R Oles: [{role: ' <role> ', db: ' <database> '} | "<role>", ...]}
User document Field Description: The user field, the name of the new user, the PWD field, the user's password, cusomdata field, for any content, for example, can be introduced to the user's full name, roles field, specify the user's role, you can use an empty array to the new user set an empty role; In the Roles field, you can specify built-in roles and user-defined roles.
Built-in Roles (built-in role): 1. Database user role: Read, readWrite; 2. Database management roles: DbAdmin, Dbowner, useradmin; 3. Cluster Management role: Clusteradmin, Clustermanager, Clustermonitor, Hostmanager; 4. Backup Recovery role: 5. backups, restore; All database roles: Readanydatabase, Readwriteanydatabase, Useradminanydatabase, Dbadminanydatabase 6. Superuser role: root//There are several roles here that indirectly or directly provide access to the system's Superuser (Dbowner, Useradmin, Useradminanydatabase) 7. Internal role: __system PS: You can click on the built-in role link above to view details about the permissions that each role has.
· Writeconcern documentation (official note) W options: Values allowed are 1, 0, values greater than 1, "majority", <tag set>; J option: Make sure Mongod instance writes data to journal (log) on disk, This ensures that no data is lost without mongd off. Set true to enable. Wtimeout: Specifies a time limit, in milliseconds. The Wtimeout only applies to W values greater than 1.
For example: Create a user AccountAdmin01 in the products database and give the user the Admin database on the clusteradmin and readanydatabase roles, the products database on the ReadWrite role. Use Productsdb.createuser ({"User": "AccountAdmin01", "pwd": "Cleartext password", "Cust Omdata ": {employeeid:12345}," Roles ": [{role:" Clusteradmin ", DB:" Admin "}, {role: "Readanydatabase", DB: "admin"}, "ReadWrite"]}, {w: "Majority", wtimeout:5000})
Verification: Mongo-u Accountadmin01-p Yourpassward--authenticationdatabase Products
From for notes (Wiz)
MongoDB Account Security operation