(1) INSERT statement, INSERT statement is done by
1, when inserting data, do not need to create a pre-set (cus), insert data will be generated automatically.
2, a primary key (_ID) is created by default each time the data is inserted without a specified field (_id)
3,_ID the same value cannot be inserted repeatedly
For example: Db.cus.insert ({name: "Zhang San", Mobile: "11111111111", email: "[email protected]", mo:200});
(2) Modify statement syntax: Db.collection.update (query,update,<upsert>,<multi>)
Query: parameter is a search selector, value type document
Update: parameter is where you need to modify the value type is document if the update parameter contains only the field option and there is no operator, a substitution change occurs.
Upsert: Optional parameter, Boolen type, default is False, when value is true, the Update method updates the matching record and inserts a new record if no matching record is found.
Multi: Optional parameter, Boolen type, default is False, when the value is true, the Update method updates all matching records.
For example: Db.cus.update ({name: "Zhang San"},{$set: {name: "John Doe"}, $inc {mo:100}}) change the specified field name and increase the field Mo field by 100.
Db.cus.update ({name: "Zhang San"},{name: "John Doe"}) changes the specified field name and clears the collection (CUS) other fields except the _id, Name field.
Db.cus.update ({name: "Zhang San"},{$set: {name: "John Doe"}},{multi:true})//change all matching records
Db.cus.update ({name: "Zhang San"},{$set: {name: "John Doe"}},{upsert:true})//change matching record, insert record if no match is found
(3) DELETE statement Delete operation has remove operation completion syntax: Db.collection.remove (<query>,<justone>)
Query: Optional parameters, search criteria
Justone: Optional parameter, Boolean value that indicates whether to delete only the first record that matches the limit 1 condition in the relational database
1. Delete all matching documents Db.cus.remove ({name: "Zhang San"})
2. Delete the first document that matches Db.cus.remove ({name: "Zhang San"},1)
3, delete all documents, but do not delete index Db.cus.remove ()
When you delete a document with remove, the Document object is also deleted from the corresponding data file on the disk.
MongoDB Add to delete operation