MongoDB Getting Started column
Http://blog.csdn.net/column/details/19681.html
Database Operations View Database
# View all databases under the current MONGO
> Show Databases
> Show DBS
Create a database
# Connect, create TestDB database
> Use TestDB
The TestDB database has been created at this time, but if you use the show DBS directive and cannot query the relevant information, this is because MongoDB does not display empty database, if you insert some data into the empty database TestDB, you can display the database;
Deleting a database
# Delete TestDB Database
> Use TestDB
> Db.dropdatabase ()
Copy Databasecan use
db.copydatabase (from_db,to_db [, From_host])to replicate the database;
# copy TestDB library to Testdb_copy Library
> Use TestDB
> db.copydatabase ("TestDB", "testdb_copy")
Renaming a databaseMongoDB does not provide instructions to rename the database, you can copy the database to achieve the renaming of the database;
# rename TestDB to testdb233
> Use TestDB
> db.copydatabase (' TestDB ', ' testdb233 ')
> Db.dropdatabase ()
But in this way, if the database is large and resource-intensive, you can use traversal to rename the collection:
# rename TestDB to testdb233
> Db.runcommand ({renamecollection: ' Testdb.orders ', to: ' Testdb233.orders '})
Collection Operations
View Collections
# Displays all collections of the specified database
> Use TestDB
> Show Collections # or Show tables
Create a collection
db.createcollection (name,option)Used to create the collection, where the option parameter is as follows: Autoindexid: If the index is automatically created in the _id field, the default is false;
Capped: Whether to create a fixed collection, when specified as True when the collection capacity to the maximum value, automatically overwrites the oldest document, when specifying capped, you must specify the size parameter;
Size: Specifies the upper limit of the size of the fixed collection, in bytes;
Max: Specifies the maximum number of documents for a fixed collection;
※ when inserting a document, MongoDB checks the size first and then checks Max;
> Use TestDB
> db.createcollection (' articles ')
> db.createcollection (' site ', {capped:true, autoindexid:true, size:233300, max:10000})
In fact MongoDB does not need to create a collection, when inserting a document, MongoDB will automatically create a collection;
Delete Collection
# Delete TestDB's site collection
> Use TestDB
> Db.site.drop ()
Renaming Collections
> Use TestDB
> db.site.renameCollection (' site233 ')