Tyl*_*ock 113
尝试:
db.collection.update(
{ '<field>': { '$exists': true } }, // Query
{ '$unset': { '<field>': true } }, // Update
false, // Upsert
true // Multi-update
)
Run Code Online (Sandbox Code Playgroud)
field您不推荐使用的字段在哪里collection,是从中删除的集合.
常规更新命令是表单db.collection.update( criteria, objNew, upsert, multi ).在false和true尾随参数禁用UPSERT模式,并支持多更新,以便查询更新所有的文档的集合(不只是第一场比赛)英寸
MongoDB 2.2+的更新
您现在可以为upsert和multi提供JSON对象而不是位置参数.
db.collection.update(
{ '<field>': { '$exists': true } }, // Query
{ '$unset': { '<field>': true } }, // Update
{ 'multi': true } // Options
)
Run Code Online (Sandbox Code Playgroud)
Jam*_*son 29
做这样的事情
db.people.find().forEach(function(x) {
delete x.badField;
db.people.save(x);
})
Run Code Online (Sandbox Code Playgroud)
哦,$unset有人在update() 这里使用的答案也非常棒.
| 归档时间: |
|
| 查看次数: |
22228 次 |
| 最近记录: |