I. Data insertion and deletion
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/99/B0/wKioL1lLRY-yfmE4AAB8EMf1VI8268.jpg "title=" 36020170622121223825.jpg "alt=" Wkiol1llry-yfme4aab8emf1vi8268.jpg "/>
(1) Insert function: DB. set name. Insert (obj,opts) obj to insert the document, OPS is an optional parameter that can be used to set the write security level.
1.insert functions can only act on a single set.
2. If the collection does not exist, the database service automatically creates the target collection.
3. If you do not specify a _id field when inserting a document, the database service automatically creates the value of the Objectid object as a _id.
(2) Bulk function: Used to batch processing insert and delete into sequential bulk and parallel bulk two kinds.
1. Initialize Bulk
Db. Collection name. Initializeunorderedbulkop () Parallel bulk
Db. Collection name. Initializeorderedbulkop () Order bulk
2. Adding data update operations to bulk
Bulk.insert (), Bulk.find.update (), Bulk.find.remove ().
3. Perform the update operation
Call Bulk.execute ()
(3) The Remove function: DB. The set name. Remove (query,justone) queries the query criteria, indicating the document to be deleted, and all documents are deleted if empty. Justone an optional parameter that uses this parameter to delete only one document that satisfies the criteria.
(4) MMAPV1 memory allocation: If an update operation exceeds the pre-allocated space on the disk for the document, MongoDB will re-allocate a larger contiguous space on the disk. The original data is then copied into the new space.
Second, MongoDB document modification
(1) Update function
Db. Collection name. Update (QUERY,OBJ,UPSET,MULTI).
Query criteria, which is equivalent to where in SQL.
Obj changes the content equivalent to the set in SQL.
Upsert whether a new document {Upsert:true} needs to be inserted when the document specified by the query criteria query does not exist.
Multi if query criteria query returns multiple documents, do you want to update all the document {Multi:true} that meet the criteria one time.
(2) Update operator
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/99/B6/wKiom1lLde6QrLZdAACmceIj4D0204.jpg "title=" 36020170622154630752.jpg "alt=" Wkiom1llde6qrlzdaacmceij4d0204.jpg "/>
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/99/B8/wKiom1lLgVKTAGuTAACsSkjXQBI278.jpg "title=" 36020170622163511489.jpg "alt=" Wkiom1llgvktagutaacsskjxqbi278.jpg "/>
650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M02/99/B8/wKioL1lLgZSTlIX3AACYcOfa3I8781.jpg "title=" 01. JPG "alt=" wkiol1llgzstlix3aacycofa3i8781.jpg "/>
Third, MongoDB write security mechanism
(1) Write process: When using insert/update/remove/save and other operations to update the data in the collection, just change the data in the memory of the image, the data is not synchronized to save on disk, before updating the in-memory data, The update operation is logged to the journal log file.
650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M02/99/BA/wKioL1lLjsLDEfryAAA9HyFiklo919.jpg "title=" 02. JPG "alt=" wkiol1lljsldefryaaa9hyfiklo919.jpg "/>
(2) MongoDB provides four levels of write security mechanisms, respectively:
Unacknowledged non-confirmed write (no result returned, no knowledge of write success)
acknowledged confirm write (return result) (only to confirm write success in memory)
journaled Log Write (can determine whether to write to disk)
Replica acknowledged copy set acknowledgement write (write operation not only for master node write acknowledgement, but also to get write acknowledgement from the node)
These four security mechanisms are higher in order and less efficient.
650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M00/99/BB/wKioL1lLmbDiaB4qAACTbhg0iwc751.jpg "title=" 03. JPG "alt=" wkiol1llmbdiab4qaactbhg0iwc751.jpg "/>
MongoDB Notes (ii)