MongoDB CREATE database and user permissions __ Database

Source: Internet
Author: User
Tags mongodb create database

Recently has been busy state, English class has not been recently, this should be lazy, wow ah oh; insist...insist...insist. Only after the busy time ... Say it today. Create a database in MongoDB ... Creating a database Check the currently selected database using command DB

>DB
Test
Use command

MongoDB use database_name is used to create a database. This command will create a new database, and if it does not exist, it will return the existing database.

Use basic syntax

Use database_name

Instance:

Use Db_detail
Switched to DB db_detail view the list of databases using the command show DBS

> Show dbs  0.000GB
The database created by MyDB does not exist in the list. To display the database, you need to insert it at least one file
> Db.customer.insert ({name: "Alan Liu"})
> show dbs
db_detail  0.000GB      0.000GB
View data tables under a library
Show Collections
Customer

* In MongoDB default database test. If no database is created, then the collection will be stored in the test database

Write this to think Oracle has user role authorization, that same mongodb should also have, check the data is true: Create user

Type the command:

> Use admin
switched to DB admin
>db.createuser ({User: "admin", pwd: "admin", Roles[{role: " Useradminanydatabase ", DB: Admin"}})
successfully added User: {
    "user": "admin",
    "roles": [
            {
                    ] Role ":" Useradminanydatabase ",
                    " db ":" Admin "
            }
    ]
}

User Login
First you need to jump to the current database mode by using the use database name, such as usage admin, and then the user logs on

Permission specific details please refer to: https://docs.mongodb.com/master/reference/method/db.createUser/

For you and the kitchen · Meet "

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.