How do I create a MONGO database and add an authenticated user to it?

Source: Internet
Author: User
Tags mongo shell

    • 0, Login Admin library, open a MONGO shell

MONGO--port 27017-u "AdminUser"-P "adminpass"--authenticationdatabase "admin"

    • 1, first switch to a new database TestDB

Use TestDB

    • 2. Create an authenticated user for the database

Db.createuser ({User: ' TestDB ', pwd: ' 111111 ', roles:[{"role": "ReadWrite", "db": "Dbenop_sandbox"}]})

    • 3, Certification

Db.auth (' TestDB ', ' 111111 ')

    • 4. Add a random piece of data

Db.test.insert ({"Test": "Test"})

    • 5, finished, see what the database is it?

Show DBS

    • Role to understand

READ: Allows the user to read the specified database
ReadWrite: Allows the user to read and write to the specified database
DbAdmin: Allows the user to perform administrative functions in the specified database, such as index creation, deletion, viewing statistics, or accessing System.profile
Useradmin: Allows the user to write to the System.users collection to create, delete, and manage users in the specified database
Clusteradmin: Available only in the admin database, giving the user administrative privileges on all shards and replica set related functions.
Readanydatabase: Only available in the Admin database, giving users read access to all databases
Readwriteanydatabase: Only available in the Admin database, giving users read and write access to all databases
Useradminanydatabase: Only available in the Admin database, giving the user useradmin permissions for all databases
Dbadminanydatabase: Only available in the Admin database, giving the user dbadmin permissions for all databases.
Root: Available only in the admin database. Super account, Super privilege

How do I create a MONGO database and add an authenticated user to it?

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.