MongoDB's database management __mongodb

Source: Internet
Author: User
Tags mongodb server
Http://www.cnblogs.com/5ishare/p/5708863.html

Previously added to the MongoDB as a service, today mainly understand the database management, before the operation of the MongoDB service open.

A. Display Database list

You can use show DBS if you want to view a list of databases.

Second, the switch database

Perform database operations by using the handle DB built into the MongoDB. The Db.getsiblings (database) method or use <database> can be used when you want to operate on different databases.

Db=db.getsiblingdb (' TestDB ')

Use TestDB

Both of these methods switch the current database handle to TestDB and set the DB value to the specified database.

Third, create a database

MongoDB does not provide a command to create the database displayed in the shell. You can use <new_database_name> to create a new database handle, but it will not actually be saved unless you add the collection to the new database. The following screenshot creates a new database handle and displays the original database when the show DBS is executed. The new database will not be available until the collection is added.

Iv. Delete Database

There is definitely a deletion of the create display, the deletion of the database is also very simple practical dropdatabase () method. The show DBS above can be seen with three databases, following the use of Dropdatabase () and looking at a few.

You can see that after you delete one, there are 2 databases left, 3-1=2.

V. Replicating databases

Copying a database creates a database that is identical to the name, typically used as a backup or archive.

Create a copy of the database, switch to the database, and then use Copydatabase (Origin,destination,[hostname]) to create a copy. The origin parameter is a string that specifies the name of the database to replicate, and the destination parameter specifies the name of the database to be created on this MongoDB server. The optional hostname parameter specifies the hostname of the Origin database MongoDB server (if the database is replicated from a different host). The screenshot below is a new newdb database that adds a set and person, and then creates a TestDB database by copying the database. Show collections can also be seen with a person collection.

---------------------------------Gorgeous split Line------------

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.