MongoDB adds user authentication: Add users, delete users, modify user passwords, read and write permissions, read-only permissions

Source: Internet
Author: User
Tags mongodb port number

1. Add and verify the user


> Use admin
> Db.adduser ("Zjx", "Tsjianxin") #添加用户

> Db.auth ("Zjx", "Tsjianxin")


These add users to the previous version of 2.6, and the 2.6 release adds the user and gives permission: View source print?

1 Use admin
2 Db.createuser ({User: "root", pwd: "Root", Roles:[{role: "ReadWrite", DB: "Admin"}]})

2. View existing users


> Db.system.users.find ()


3. Now to configure a user with read and write access to another database 51CV


> Use 51CV
> Db.adduser ("51CVRW", "51CV")
... "readOnly": false ...


4. Configure a user with read-only permissions


> Use 51CV
> Db.adduser ("51cvr", "51CV", True)
> Db.system.users.find ()
... "readOnly": True ...


5. Delete a user


> Use dbname (admin or 51CV, etc)
> Db.system.users.remove ({User: "haha"})
> Db.system.users.find ()


6. User Login Database Test


MONGO Admin-u zjx-p tsjianxin

/usr/local/mongodb/bin/mongo admin-u user name-p password--port port number

Add users to the previous version 2.6, 2.6 later: View source print?

1 ./bin/mongo-u user-p Password 127.0.0.1:27017/dbname
<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<


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.