mongodb--Database and collection considerations

Source: Internet
Author: User

<strong> Precautions:</strong>
1, database name attention should be all lowercase, cannot contain spaces, the maximum length is 64K name <br/>
2, the database is stored as multiple files, library name: Per, File: Per1, Per2, library name: Sun, File: Sun1, Sun2, etc., but the maximum single file is 2g<br/>
3. The namespace metadata corresponding to the collection and index is saved in the. ns file <br/>
<br/>
<br/>

Table:
1, stored data word Keweikiang type, "age" and "age" is two different attributes <br/>
2, the same row of data can not be repeated <br/>
3, the column name is sequential, the same column name and content, the order is different from 2 records, {"Name": 1,&quot;age&quot;:2} &nbsp; with {&quot;age&quot;:2, "name": 1 } is two records <br/>
4, try to put the same structure of the document in a collection, because the created index page will have a structure. Data from different structures can affect index efficiency <br/>
5, Db.createcollection (&quot; xxxxx&quot;) Create a collection <br/>
6, when the instance starts with the--objcheck option, the object database inserted content to do the check, invalid format does not allow the insertion of <br/>
7, {"$addToSet": {"emails": "[email protected]"}} &nbsp; if the collection exists then do not add, create <br if it does not exist/>
8. Use {"$addToSet": {"emails": {"$each" $addToSet $each Email protected]&quot;,&quot; [email Protected]&quot;]}}} , batch additions, and whether there is a judgment. <br/>
9, $pop Array delete operation {&quot; $pop &quot;:{&quot;emails&quot;:-1}} to remove a {&quot; $pop &quot;:{& Quot;emails&quot;:1}} end deletes a <br/>
10. The array can be modified with subscript index db.sun.update ({&quot;name&quot;:&quot;sun&quot;},{"$set": {&quot;like.0 &quot;:&quot;haha&quot;}}) &nbsp; Modify the first data inside a like array <br/>
11, the contents of the array collection can also be updated according to the conditions, using the $ symbol <br/>
<span style= "White-space:pre" ></span>db.sun.update ({&quot;address.city&quot;:&quot; shanghai&quot;},{&quot; $set &quot;:{&quot;address.$.state&quot;:&quot; Hh&quot;}}) <br/>
<span style= "White-space:pre" ></span> Modify sub-object <br/> Based on sub-object condition search
12, the Update method, the 3rd parameter is not present to create, the 4th parameter is whether the batch modification can be made, by default, according to the query to modify the matching to the first <br/>
13, Db.runcommand ({getlasterror:1}) gets the situation of the last update <br/>
14, Findandmodify () &nbsp;//query, perform the update or delete, <br/>
<span style= "White-space:pre" ></span>db.runcommand ({&quot;findandmodify&quot;:&quot; table name &quot;,<br/>
<span style= "White-space:pre" ></span>&quot;query&quot;:&quot; query conditions &quot;,<br/>
<span style= "White-space:pre" ></span>&quot;sort&quot;:&quot; sorting criteria &quot;,<br/>
<span style= "White-space:pre" ></span>&quot;update&quot;:&quot; content updated based on query criteria &quot;< br/>
<span style= "White-space:pre" ></span>&quot;remove&quot;:false,//&quot; Delete and update can only exist one & Quot;<br/>
<span style= "White-space:pre" ></span>&quot;new&quot;:false//The records returned are pre-or post-update})

mongodb--Database and collection considerations

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.