node.js - mongodb 批量更新文字 增加部分内容.
迷茫
迷茫 2017-04-17 13:15:43
0
2
545

求教个 mongodb 的问题:

想向字段内增加文字, 比如 "name":"john"

想改成 "name":"name john"

想批量 update 怎么改呢?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
阿神

The last one is updated one by one, there is no other way.

黄舟

db.collection.update(criteria, objNew, upsert, multi)
criteria: update query conditions, similar to
objNew: update object and some update operators after where in sql update query ( Such as $, $inc...), etc., which can also be understood as the
upsert after set in the sql update query: This parameter means whether to insert objNew if there is no update record, true means insert, and the default is false, do not insert.
multi: The default value of mongodb is false. Only the first record found is updated. If this parameter is true, all multiple records found according to the conditions will be updated.

For example:
db.collection.update({"isValid":1}, {$set:{ "name" : "name john"}}, false, true)
Set the value of isValid to The names of all records of 1 are set to "name john"

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template