I learned the update statement and the $ push modifier. The example in the book makes me puzzled. The first two parameters of update () are query and new documents. The example in the book is as follows:
I learned the update statement and the $ push modifier. The example in the book makes me puzzled. The first two parameters of update () are query and new documents. The example in the book is as follows:
I learned the update statement today and the $ push modifier. The example in the book makes me puzzled. The first two parameters of update () are query and new documents. The example in the book is as follows. Find the Key in the set as Gende rather than the Mr item. After finding it, set its Gender to M. According to my idea, no one has the Gendar attribute. If the conditions are not met, the new documents will not be generated, but the execution results will be quite different, because no document has the Gender attribute, the first document is returned, and the Gender attribute is added to the during of the first document!
> Db. test. remove ()
> Db. test. insert ({"name": ""})
> Db. test. insert ({"name": "puncha "})
> Db. test. find ()
{"_ Id": ObjectId ("50c21581810234135d194bcc"), "name": ""}
{"_ Id": ObjectId ("50c21586810234135d194bcd"), "name": "puncha "}
> Db. test. update ({"Gender": {"$ ne": "M" }}, {"$ push": {"Gender": "M "}})
> Db. test. find ()
{"_ Id": ObjectId ("50c21586810234135d194bcd"), "name": "puncha "}
{"Gender": ["M"], "_ id": ObjectId ("50c21581810234135d194bcc"), "name": "du
Ring "}
>