MongoDB database & set operations,
Database Operations to view databases?
# View all databases in the current mongo
> show databases ?
> show dbs
Create a database ??
# Connect to create a testdb Database
> use testdb
At this time, the testdb database has been created. However, if the show dbs command is used, the related information cannot be queried. This is because mongodb does not display empty databases. If some data is inserted into testdb, the database is displayed. Delete the database?
# Deleting a testdb Database
> use testdb
> db.dropDatabase()
Copy a database
Db. copyDatabase (from_db, to_db [, from_host])To copy the database ;?
# Copy the testdb database to the testdb_copy Database
> use testdb
> db.copyDatabase("testdb", "testdb_copy")
Mongodb does not provide commands to rename a database. You can rename a database by copying the database ;?
# Rename testdb to testdb233
> use testdb
> db.copyDatabase('testdb', 'testdb233')
> db.dropDatabase()
However, if the database is large enough to occupy resources, you can use traversal to rename the set :?
# Rename testdb to testdb233
> use testdb
> db.runCommand( { renameCollection:'testdb.orders', to: 'testdb233.orders' } )
Set operation view set?
# Display all sets of the specified database
> use testdb
> Show collections? # Or show tables
Create a set
Db. createCollection (name, option)Used to create a set. The optional options are as follows:
AutoIndexID: whether to automatically create an index in the _ id field. The default value is false;
Capped: whether to create a fixed set. If it is set to true, when the set capacity reaches the maximum value, the earliest documents will be automatically overwritten. When capped is specified, the size must be specified? Parameters;
Size: specifies the maximum size of a fixed set, in bytes;
Max: specifies the maximum number of documents in a fixed set;
※When inserting a document, mongodb first checks the size and then max ;?
> use testdb
> db.createCollection('articles')
> db.createCollection( 'site', { capped:true, autoIndexID:true, size:233300, max: 10000} )
Actually mongodb? You do not need to create a set. When you insert a document, mongodb will automatically create a set and delete the set?
# Delete the site set of testdb
> use testdb
> db.site.drop()
Rename a set?
# Rename the site set of the testdb database to site233
> use testdb
> db.site.renameCollection('site233')