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------------