Mongodb Study Notes 05-user management

Source: Internet
Author: User

Mongodb Study Notes 05-user management
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: "
  
   ",  pwd: "
   
    ",  customData: {  },  roles: [    { role: "
    
     ", db: "
     
      " } | "
      
       ", ... ]}
      
     
    
   
  

writeConcern:

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

W option: values allowed are 1, 0, greater than 1, "majority", and j option: ensure that the mongod instance writes data to the journal (log) on the disk ), this ensures that data is not lost when you disable 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 superuser role: root
// Here, there are several roles that indirectly or directly provide access to system superusers (dbOwner, userAdmin, userAdminAnyDatabase) internal roles :__ 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)

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.