MongoDB Learning Note 05--User Management

Source: Internet
Author: User
Tags auth time limit

Enable authentication

Mongod boot is not enabled by default, you need to specify –auth boot, 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

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

Writeconcern:

For example {w: "Majority", J:true, wtimeout:5000}

    • W Options: Allowable values are 1, 0, values greater than 1, "majority",;
    • J option: Ensure that the Mongod instance writes data to the journal (log) on disk, which ensures that no data is lost outside of the mongd. Set true to enable.
    • Wtimeout: Specifies a time limit, in milliseconds. The Wtimeout only applies to W values greater than 1.

Built-in Roles (built-in role):

    • Database user role: Read, readWrite;
    • Database management roles: DbAdmin, Dbowner, useradmin;
    • Cluster Management role: Clusteradmin, Clustermanager, Clustermonitor, Hostmanager;
    • Backup recovery role: backups, restore;
    • All database roles: Readanydatabase, Readwriteanydatabase, Useradminanydatabase, dbadminanydatabase
    • Super User role: Root
      There are also several roles that indirectly or directly provide access to the system's Superuser (Dbowner, Useradmin, Useradminanydatabase)
    • Internal role: __system

Creatuser Example

Create a Super Administrator

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

Create AccountAdmin01 users in the products database, with ReadWrite permissions, Clusteradmin and Readanydatabase permissions to the admin database

use"user""accountAdmin01",                 "pwd""cleartext password",                 "customData"12345 },                 "roles""clusterAdmin""admin" },                             "readAnyDatabase""admin" },                             "readWrite"                             ] },               "majority"5000 } )
Login
use collectionNamedb.auth("username",‘password")
View User
show users
Delete User
db.dropUser("username")
change user Password
db.changeUserPassword("username","password")
Update user
db.createUser(user, writeConcern)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MongoDB Learning Note 05--User Management

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.