Create and delete a MongoDB Database

Source: Internet
Author: User
Tags install mongodb

Create and delete a MongoDB Database
MongoDB database creation syntax

The syntax format for creating a MongoDB database is as follows:

use DATABASE_NAME

If the database does not exist, create a database. Otherwise, switch to the specified database.

Instance

The following instance creates the database runoob:

> use runoobswitched to db runoob> dbrunoob>

To view all databases, run the show dbs command:

> show dbslocal  0.078GBtest   0.078GB>

We can see that the created database runoob is not in the Database List. to display it, we need to insert some data to the runoob database.

> Db. runoob. insert ({"name": ""}) WriteResult ({"nInserted": 1})> show dbslocal 0.078 GBrunoob 0.078 GBtest 0.078 GB>

The default database in MongoDB is test. If you do not create a new database, the set will be stored in the test database.

 

 

MongoDB database deletion syntax

The syntax format for deleting a MongoDB database is as follows:

db.dropDatabase()

Delete the current database. The default value is test. You can use the db command to view the current database name.

Instance

The following instance deletes the database runoob.

First, view all databases:

> show dbslocal   0.078GBrunoob  0.078GBtest    0.078GB

Next we switch to the database runoob:

> use runoobswitched to db runoob> 

Run the DELETE command:

> db.dropDatabase(){ "dropped" : "runoob", "ok" : 1 }

Finally, run the show dbs command to check whether the database is successfully deleted:

> show dbslocal  0.078GBtest   0.078GB> 

For more MongoDB tutorials, see the following:

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

MongoDB beginners must read (both concepts and practices)

MongoDB Installation Guide for Ubunu 14.04

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

Nagios monitoring MongoDB sharded cluster service practice

Build MongoDB Service Based on CentOS 6.5 Operating System

MongoDB details: click here
MongoDB: click here

This article permanently updates the link address:

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.