MongoDB Authorized Login

Source: Internet
Author: User
Tags mongodb version

MongoDB version 3.2 (currently up-to-date), the demo is the Linux under the MongoDB authorization authentication

First logon does not start authorization (MONGO default does not start)

  

./mongod--dbpath=/home/db/data--logpath=/home/db/logs/mongodb.log

Then use the./mongo command to connect to the database

./mongo

Switch to admin database use Admin

Use the Create user command:

  

Use Admindb.createuser (  {    "Coderhuang",    "123456",    "root", DB: "admin"  } ]  })

A user named Coderhuang is added to the admin database (Note: MONGO provides a set of user rights for each database)

Then close the database (note: When authorization authentication is initiated, only the root role has permission to shut down the database)

Db.shutdownserver ();

  

Second logon enables authorization authentication:

./mongod--auth--dbpath=/home/db/data--logpath=/home/db/logs/mongodb.log

Then switch to the Admin database and use the View User command

Use Adminshow Users

The prompt is not authorized

Authorization is required at this time.

Db.auth ("Coderhuang", "123456");

Then you can see the user information by calling the command just now.

Then we need to add the relevant users to our database, where we use db_report as an example

Use db_reportdb.createuser ({   "client",   "111111",   roles: [      "ReadWrite" , DB: "Db_report" }   ]})

This adds a role with read and write permissions to the Db_report database.

To this, MONGO authorized to complete

MongoDB Authorized Login

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.