The basic DDL for getting started with MongoDB

Source: Internet
Author: User
Tags mongodb collection

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

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.