MongoDB Basic Operation statement

Source: Internet
Author: User
Tags numeric value

#MongoDB中有三元素: A database, a collection, a document, where "set" is the "table" in the corresponding relational database, and "document" corresponds to "row". #创建数据库testdb数据库, mongos> use testdb; #查询数据库 with the following statement to show that the database must be inserted at least one document mongos> show dbs;# Insert Data document Mongos> db.tablename.insert ({"Name": "Antian"}); #数据库生成了mongos > show dbs;testdb   0.078gb# Delete Database # Query database mongos> show dbs;testdb  0.078gb# Enter database Mongos> use  testdb; #删除数据库mongos > db.dropdatabase (); {  "Dropped"  :  "TestDB",  "OK"  : 1 } #查询数据库mongos > show dbs;# MongoDB data type MongoDB supports a list of many data types below given:string :  this is the most commonly used data type to store data. The string in MongoDB must be a valid UTF-8. integer :  This type is used to store a numeric value. The integer can be either 32-bit or 64-bit, depending on your server. boolean :  This type is used to store a Boolean value   (True/ false)  . double :  This type is used to store floating-point values. min/ max keys :  This type is used to compare the lowest and highest values of the Bson element. arrays :  uses this type of array or list or multiple values to store to a key. timestamp :  time stamp. This makes it easy to record when the file has been modified or added. object :  This data type is used for embedded files. null :  This type is used to store a null value. Symbol :  This data type is used for the same string, but it is usually reserved for use by a language of a particular symbol type. date :  This data type is used to store the UNIX time format for the current date or time. You can specify your own date and time, date and year, month, day to create an object. object id :  This data type is used to store the document ID. binary data :  This data type is used to store binary data. code :  This data type is used to store JavaScript code in a document. regular expression :  This data type is used to store the regular table # Create a collection # Enter database mongos> use testdb; #创建集合mongos >  db.createcollection ("mycollection") mongos> show tables;mycollection# Delete Collection # Enter database mongos>  use testdb;mongos> show tables;mycollectionmongos> db.mycollection.drop (); truemongos> show tables; #插入文档 # Insert a document Mongos> db.tablesname.insert ([{"Name": "AAAAA", "Age": " "} #插入两条文档mongos > db.tablesname.insert ([{" Name ":" Ddddd "," Age ":"},{"," name ":" Eeee "," Age ":" 10 "}]); Format Query document Mongos> db.tablename.find (). Pretty (); #查询一个文档: Mongos> db.tablesname.findone (); #更新文档 # Display Collection document Mongos> db.v.find (); {  "_id"  : objectid ("55113e5477eaee1608881c84"),  "name" &Nbsp;:  "Antian"  } #更新文档mongos > db.tablename.update ({"Name": "Antian"},{"name": "Wuhan"}); Display Collection document Mongos> db.tablename.find (); {  "_id"  : objectid ("55113e5477eaee1608881c84"),  "name"  :  "Wuhan"  } #删除文档 # Delete Document content Mongos> db.tablename.remove ({"Name": "Wuhan"}); #删除文档: Db.tablename.drop (); #投影db. Tablename.find ({}, {"SIP": 1,_id:1}); #限制记录mongos > db.tablename.find ({},{"sip": 1,_id:0}). Limit (2); #排序文档 # Descending Mongos> db.tablename.find ( {},{' age ': 1,_id:0}). Sort ({"Age": -1}), #升序mongos > db.tablename.find ({},{"age": 1,_id:0}). The sort ({"Age": 1}); #创建索引mongos > db.tablename.ensureindex ({"id": 1}) #mongos > db.tablesname.stats (); #数据库集合解释 {" Sharded " : false, #分片" PRIMARY " : " shard0001 "," ns " : " 6xx.testdocument01 ", #集合命令" Count " : 2100, #集合文档总数" size " : 504000, #集合空间大小, in bytes" Avgobjsize " : 240, #平均对象占用的空间" Numextents " : 4, #连续分配的数据库" Storagesize " : 696320, #给整个集合分配的空, this value does not degrade the "lastextentsize"  : 524288 when the collection document is deleted, #最近分配的块的大小 "Paddingfactor"  : 1,# " Paddingfactornote " : " paddingfactor is unused and unmaintained in 3.0.  it remains hard coded to 1.0 for compatibility only. "," userFlags " : 1," capped " : false," nindexes " : 1," Totalindexsize " : 81760,# Sum of all index sizes "indexsizes"  : {#列出集合的所有索引字段, and index size "_id_"  : 81760}, "OK"  : 1}


This article is from the "Wu Shanqiang" blog, make sure to keep this source http://shanqiangwu.blog.51cto.com/8067564/1653577

MongoDB Basic Operation statement

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.