Let's start with a MongoDB program (PHP) Related issues:
In the development, I need to update the corresponding document content according to the _id of a document, when I use a string like this directly ("57584E289BEF19798BD1CAB4"), the direct array ("_id" = " 57584e289bef19798bd1cab4 "), found that the update failed, including conversion to object type is not possible, and finally know that you need to use MongoDB inside the method to convert:$id = New MongoId ($id), converted results
Only converted to this, can be identified by MongoDB, and then directly array ("_id" and $id) on it;
One, MongoDB update document (Speaker update ())
The MongoDB update document uses the update () method, but there is also a way to save (), although save () is the insertion method, but it has a mechanism that it scans all documents in the corresponding collection before executing the INSERT, to see if the inserted data exists in the collection, if there is , then call the MongoDB Update () method, update (overwrite), do not exist then insert;
The syntax for update in MONGODB:
Db.collectionName.update ({condition},{requires modified field and value},{upsert/multiple})
The update () operation of MongoDB focuses on modifiers:
1. $inc : specifically used to increase or decrease numbers, only for integers, long integers, and double-precision floating-point numbers, the value of $inc key must be a number, cannot be an array, string, or other non-numeric value, if the key does not exist, it is created
$inc Add Direct Write number (reward:5), subtract (reward:-5), non-existent field directly created, note that must be a numeric type, cannot be an array or other non-numeric value such as a string
2. $set : used to specify the value to modify a field, the value of the other field is not changed, to avoid overwriting the entire document, the updated field does not exist to create
3. $unset: Delete a field (unset only knows the form of key:value, so the value behind it doesn't matter, as long as it sees the key will unset off)
4. Array modifiers
Continued: http://wangming1993.github.io/2015/12/15/mongo-modifier/
MongoDB Update Documentation