<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,"age":2} with {"age":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 (" xxxxx") 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]"}} if the collection exists then do not add, create <br if it does not exist/>
8. Use {"$addToSet": {"emails": {"$each" $addToSet $each Email protected]"," [email Protected]"]}}} , batch additions, and whether there is a judgment. <br/>
9, $pop Array delete operation {" $pop ":{"emails":-1}} to remove a {" $pop ":{& Quot;emails":1}} end deletes a <br/>
10. The array can be modified with subscript index db.sun.update ({"name":"sun"},{"$set": {"like.0 ":"haha"}}) 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 ({"address.city":" shanghai"},{" $set ":{"address.$.state":" Hh"}}) <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 () //query, perform the update or delete, <br/>
<span style= "White-space:pre" ></span>db.runcommand ({"findandmodify":" table name ",<br/>
<span style= "White-space:pre" ></span>"query":" query conditions ",<br/>
<span style= "White-space:pre" ></span>"sort":" sorting criteria ",<br/>
<span style= "White-space:pre" ></span>"update":" content updated based on query criteria "< br/>
<span style= "White-space:pre" ></span>"remove":false,//" Delete and update can only exist one & Quot;<br/>
<span style= "White-space:pre" ></span>"new":false//The records returned are pre-or post-update})
mongodb--Database and collection considerations