MongoDB CREATE Database

Source: Internet
Author: User
Tags mongodb create database


Use command

MongoDB creates a database in the same way as use + database name. Use creates a new database and returns the database if it exists.
Syntax format

The basic format of the use statement is as follows:

Use database_name
Example

Create a database named, using the USE statement as follows:

>use MyDB
Switched to DB MyDB

Use the command DB to check the currently selected database.

>db
MyDB

Use the command show DBS to check the database list.

>show DBS
Local 0.78125GB
Test 0.23012GB

The database you just created (mydb) does not appear in the list. In order for the database to appear, at least one document should be inserted.

>db.mydb.insert ({"Name": "Tutorials Point"})
>show DBS
Local 0.78125GB
MyDB 0.23012GB
Test 0.23012GB

In MongoDB, the default database is test, and if you do not create any databases, the collection is saved in the test database.

MongoDB Database Creation

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.