MongoDB User Rights Management

Source: Internet
Author: User

Authorized users ReadWrite have read and write access to the Test1 library:

> use test1switched to db test1> db.createUser({user: "readwrite",pwd: "readwrite",customData: {description: "测试用户readwrite"},roles: [{role: "readWrite",db: "test1"}]})

Verify that the authorization is correct:

mongo -ureadwrite -preadwrite --authenticationDatabase test1MongoDB shell version: 3.2.16connecting to: test

Note: The user authorization must abide by the specification, otherwise may appear not even on the situation, to give an example

 mongo -uroot -proot --authenticationDatabase adminMongoDB shell version: 3.2.16connecting to: test>  db.createUser({... user: "readwrite1",... pwd: "readwrite1",... customData: {... description: "测试用户1"... },... roles: [{... role: "readWrite",... db: "test1"... }]... })

We created the readwrite1 user, which differs from the previous ReadWrite user in that it is authorized under the test library,

mongo -ureadwrite1 -preadwrite1 --authenticationDatabase test1MongoDB shell version: 3.2.16connecting to: test2018-02-08T23:17:20.762+0800 E QUERY    

You can see that if--authenticationdatabase does not have an authorized library to connect to the MONGO service, there are two workarounds to avoid similar situations:
1, create the user when created under the test library, because the default connection is the test library
2, first switch to the library you want to authorize to create a user
The second approach is recommended, in any case it is best to fix it in a way that saves the cost of communication with development

MongoDB Role Table

MongoDB User Rights 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.