Objective:
This article mainly records the partial DDL operations of the main MongoDB Collection.
- DB view current database (default test)
> dbtest >
- Show DBS View database names on the current database server
> Show Dbsadmin (empty) Local 0. 078GBmydb 0. 078GBtest (empty) >
- Use DbSchema to switch to a database context named DbSchema
> Use to db mydb>
When the database is created with the name DbSchema not present, the database created with use will not be deleted when the switch to another database is not saved.
- Db.dropdatabase () Delete the database where the current period resides
>1 }>
- Db.stats () View the status of database
>db.stats () {"db": "MyDB", "Collections":3, "Objects":6, "avgobjsize": the, "datasize":480, "storagesize":24576, "numextents":3, "Indexes":1, "indexsize":8176, "fileSize":67108864, "Nssizemb": -, "datafileversion": {"Major":4, "minor":5}, "Extentfreelist": {"num":2, "totalsize":262144}, "OK":1}>
- Show collections View collections within the current database
> Show Collectionscollectsystem.indexes >
- Db.collection.stats () View the status of a collection
>db.collect.stats () {"ns": "Mydb.collect", "Count" :2, "size":224, "avgobjsize": the, "storagesize":8192, "numextents":1, "nindexes":1, "lastextentsize":8192, "Paddingfactor":1, "systemflags":0, "userflags":1, "totalindexsize":8176, "indexsizes": {"_id_":8176}, "OK":1}>
- Db.createcollection (name,options) Create a collection
Db.createcollection (name, {capped: <boolean>, Autoindexid: <boolean>, size: <number>, Max <number })
> db.createcollection (... ") Test ",... {... Capped:true,... Autoindexid:true,... 1024x768 1 }>
Name: Collection of names
Capped: Whether to enable the collection limit, if you need to set a restriction, the default is not enabled, if you want to turn on the Size,max limit, you need to turn on capped
Size: Limits the amount of space used by the collection, which is not limited by default
Max: Limit of maximum number of bars in the collection, defaults to No limit
AUTOINDEXID: Whether to use _id as the index, by default (TRUE or FALSE)
Size has a higher priority than max
- Db.yourColl.drop () Delete collection
> db.test. Drop () True >
The basic DDL for getting started with MongoDB