I recently started reading some articles about MongoDB, and I feel more and more that it is what I need. However, I don’t know much about it first, and what I see are superficial phenomena, let’s get to know it slowly.
I started reading the introduction to MongoDB written by Carl yesterday. It has 33 pages in total. I feel that the article is not very clear, and I need to try and experience it myself.
For traditional databases, CRUD (=Create+Read+Update+Delete) is the core, and U is the most worthy of attention! Today, I read the introduction of the Update part and practiced it.
Update has 4 parameters: the first, selector, the second, newValue, the third, upserts, the fourth, multipleUpdate
The selector is the same as the CRD, it is a search selector that specifies the query conditions;
newValue is the content to be updated, including two basic situations, that is, whether there are parameters such as $set, $inc, and $push:
Case 1, if there is no parameter, then newValue replaces the content of the original selector;
Case 2, if there are parameters, then $set is to update newValue for the specified field; $inc requires the specified field to be a value, plus newValue; $push requires the specified field to be an array, and newValue is added to the array. Of course, there must be many more parameters, and I only learned so much first!
I won’t go into details, just type the code once and you’ll know what it means;
upserts is a logical value parameter, the default is false, that is, according to the selector query, if the document is found, it will be updated; if it is not found, it will do nothing. If it is set to true, the meaning is obvious. If it is not found, create a new document to store the selector and newValue.
multipleUpdate is also a logical value parameter, the default is false, that is, according to the selector query, if the documents are found, then the first document will be updated; if it is set to true, all the found documents will be updated.