MongoDB Learning Note 05--User Management

Source: Internet
Author: User

Csdn's Markdown editor is really bad enough, this article is lost again

Enable authentication

Mongod boot is not enabled by default, you need to specify –auth boot. or set the 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: {  },  roles: [    "<role>""<database>""<role>",    ...  ]}

Writeconcern:

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

W Options: The agreed values are 1, 0, values greater than 1, "majority", "j" option: Ensure that the Mongod instance writes data to the journal (log) on the 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 is only suitable for 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 system super users (Dbowner, Useradmin, Useradminanydatabase)
    • Internal role: __system
Creatuser Sample Example

Create a Super Administrator

db.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

db.createUser"user""accountAdmin01",                 "pwd""cleartext password",                 "customData"12345 },                 "roles""clusterAdmin""admin" },                             "readAnyDatabase""admin" },                             "readWrite"                             ] },               "majority"5000 } )
Login
db.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)

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.