MongoDB Self-study diary 2

Source: Internet
Author: User
Tags auth mongodb version

The first thing to be clear is why you should learn MongoDB. OK, if only for the original interest in popular technology, may not be able to study deeply, there must be application requirements. Just started to learn MongoDB, because the previous knowledge of other databases is not particularly deep, so many concepts and principles need to comb.

This section is focused on learning access control permissions. The first step is to create the user, with some MongoDB documents at hand, however, it is estimated that the publication time and version is too old, basically said to create the user with Db.adduser, the result is unsuccessful execution. The reason is that the MongoDB version I use is 3.0.6, and since the 2.6 version has been deprecated AddUser this method, replaced by CreateUser (it seems to be more to see the official manual).

1. After connecting to the database, switch to the admin database. MongoDB will have an admin database by default, creating users that need to use this database.

>use Admin

2. Create a user with root privileges

>db.createuser ({User:"username"pwd:"  123456", roles:["root"]})

3. Change user Password

>db.changeuserpassword ("username","newpassword");

4. View user Information

>db.runcommand ({userInfo:"username"}){       "OK":0,       "errmsg":"no such command:userinfo",       "Code": -,       "Bad cmd" : {               "UserInfo":"username"       }}

5. Login

$mongo-  u username-p password--authenticationdatabase admin

6. Verify the user, the Auth method verifies that by returning the value 1, the error returns 0.

>db.auth ("username","password");

7. View Current User permissions

>db.runcommand (  {    usersinfo:"username",    showprivileges:  true  })

With the root user, you can add a few more ordinary users, such as read-only permissions.

> db.createuser ({    User:'xiaoh',    pwd:' 123456 ' ,    roles:[    'read',     '  Dbadminanydatabase']   })

We can also bind the server to the IP and port, which limits the IP and port that can access MongoDB on the service side.

$mongod  --bind_ip  192.168.  1.28   --port  28018

  

Write so much first, and finally attach a recent personal exercise ("The hacker and the painter brainwashed"). Stand a flag here, and every article must take a hand-painted or not, if any of the words, please all the message of the Netizen to eat.

Hand Brush, hand codewalking the river, laughing proud of the horizon

References:

1. In-depth study of MongoDB

2. The MongoDB authoritative guide

Links:

1.https://docs.mongodb.org/master/reference/built-in-roles/#database-administration-roles

2.http://www.cnblogs.com/huangxincheng/archive/2012/02/18/2356595.html

3.http://blog.csdn.net/yenange/article/details/43966799

MongoDB Self-study diary 2

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.