Mongodb Study Notes 05 and mongodb Study Notes

Source: Internet
Author: User

Mongodb Study Notes 05 and mongodb Study Notes
Enable authentication

Mongod does not have the permission to start by default. You need to specify-auth to start, or set security. authorization to "enabled" in the configuration file"

Create user

Db. createUser (user, writeConcern)

  • Document http://docs.mongodb.org/manual/reference/method/db.createUser/#db.createUser

User format

{ user: "<name>",  pwd: "<cleartext password>",  customData: { <any information> },  roles: [    { role: "<role>", db: "<database>" } | "<role>",    ...  ]}

WriteConcern:

For example, {w: "majority", j: true, wtimeout: 5000}

  • W option: values allowed are 1, 0, greater than 1, "majority", and ",;
  • J option: Make sure that the mongod instance writes data to the journal (log) on the disk. This ensures that data is not lost when it is disabled outside mongd. Set true to enable.
  • Wtimeout: specifies a time limit, in milliseconds. Wtimeout is applicable only when the value of w is greater than 1.

Built-In Roles (built-in role ):

  • Database User Roles: read and readWrite;
  • Database management roles: dbAdmin, dbOwner, and userAdmin;
  • Cluster management roles: clusterAdmin, clusterManager, clusterMonitor, and hostManager;
  • Backup and recovery roles: backup and restore;
  • All Database roles: readAnyDatabase, readWriteAnyDatabase, userAdminAnyDatabase, and dbAdminAnyDatabase
  • Super User role: root
    // There are also several roles that indirectly or directly provide system superuser access (dbOwner, userAdmin, userAdminAnyDatabase)
  • Internal role :__ system

CreatUser example

Create a super Administrator

use admindb.createUser({    user:"username",    pwd:"password",    roles:["root"]})

Create an accountAdmin01 user in the products database and have the readWrite permission. You have the permissions of clusterAdmin and readAnyDatabase on the admin database.

use productsdb.createUser( { "user" : "accountAdmin01",                 "pwd": "cleartext password",                 "customData" : { employeeId: 12345 },                 "roles" : [ { role: "clusterAdmin", db: "admin" },                             { role: "readAnyDatabase", db: "admin" },                             "readWrite"                             ] },               { w: "majority" , wtimeout: 5000 } )
Login
use collectionNamedb.auth("username",'password")
View users
show users
Delete a user
db.dropUser("username")
Change User Password
db.changeUserPassword("username","password")
Update user
db.createUser(user, writeConcern)

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.