MongoDB creates a user for the database

Source: Internet
Author: User
Tags auth

Transfer from http://www.imooc.com/article/18439

First, start MongoDB in a non-authoritative mode.
Non-authorized:

Linux/mac:mongod-f/mongodb/etc/mongo.conf

Windows:mongod--config c:\mongodb\etc\mongo.conf or net start MongoDB (provided MONGO is installed in the service)

Note:

/mongodb/etc/mongo.conf bit MONGO the address where the configuration file resides

Authorized:

Mongod-f/mongodb/etc/mongo.conf--auth

Note:

1.--auth on behalf of authorization to start, need account password to access

2.auth=true can be added to the mongo.conf configuration file for unified management

Two. Create an administrator
1. Start MONGO in a non-authorized manner

2. Create the Admin database

Use admin

3. Add Admin user
Db.createuser ({User: "admin", pwd: "123456", roles:["root"]})

Note: User name and password can be arbitrarily determined

4. Certifications

Db.auth ("admin", "123456")

Three. Start MONGO in an authoritative manner to add users to the database you are using
1. Switching the database

Use test

2. Create a user

Db.createuser ({User: "root", pwd: "123456", roles: [{role: "Dbowner", DB: "Test"}]})

3. Connect the test database via the client



MongoDB creates a user for the database

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.