mongodb 如何移除某个 collection 下所有 document 的某个 field?

浏览:31日期:2023-07-11

问题描述

有的 document 包含某个 field,有的又不包含。准备移除某个 collection 下所有 document 的某个 field,该怎么做?

问题解答

回答1:

mongo shell

db.foo.update({}, {$unset: {bar: true}}, {multi: true});回答2:

collection.update xxoo: $exists: true, $unset: xxoo: true, multi: true, ->回答3:

unset遍历移除.如果条目较多,会影响数据库性能,需谨慎.

相关文章: