MongoDB Open User name password verification

Source: Internet
Author: User

MongoDB will present all user information in the collection System.users of the admin database, which mainly includes the user name, password, and database information. MongoDB does not enable authentication by default, as long as it can connect to the server, it can connect to Mongod. To enable security authentication, you need to change the registry under Windows, and then change the configuration file under Linux. Only the actions under Windows are described here.

First, create an administrator user

1 Viewing the database with show DBS, finding that the admin database could not be found

2 Create user admin

Db.createuser (

{

"User": "admin",

"pwd": "admin",

Roles:[{role: "Useradminanydatabase", DB: "admin"}]

}

)

Displays the user who created the admin successfully.

3 query All the databases, you can see the admin database is displayed

4 Querying the collection and the data in the collection

5 Turn on login verification

Enter the system registry and locate [Hkey_local_machine-->system-->currentcontrolset-->services-->mongodb] on the right-hand side of the health-value list " ImagePath "

Add--auth to the ImagePath corresponding value, i.e.

"D:\Program files\mongodb\server\3.2\bin\mongod.exe"--dbpath=e:\db "--logpath=d:\program files\mongodb\server\3.2 \logs\mongodb.log "--auth--service

After the change, restart the MongoDB service,

6 Login MongoDB with non-authentication method, and query the collection, report the error without permission

7 Login with username and password

A return value of 1 indicates that the login was successful.

8 Query collection again to display the results normally

Second, create a regular user

> Use test

> Db.createuser (

{

User: "Test1",

PWD: "Test1",

Roles: [{role: ' ReadWrite ', DB: ' Test '}]

}

)

Show user Creation success

Log in with a user name and password and query the collection

MongoDB Open User name password verification

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.