{ 
    name: 'book',
    tags: {
        words: ['abc','123'],
        lat: 33,
        long: 22
    }
}

假设这是一个文档。我如何从这个集合中的所有文档中完全删除“单词”?我希望所有的文件都没有“文字”:

 { 
     name: 'book',
     tags: {
         lat: 33,
         long: 22
     }
}

当前回答

因为我一直在寻找使用蒙古引擎删除字段的方法时找到这个页面,我猜在这里发布蒙古引擎的方式也可能有帮助:

Example.objects.all().update(unset__tags__words=1)

其他回答

对于monomapper来说,

文档:关闭 需要移除的字段:shutoff_type

Shutoff.collection。更新 ( {}, { '$ 设置' = >{“shutoff_type”:1}},:多= > true)

删除或删除MongoDB中的字段

单次记录 db.getCollection(“用户数据”)。更新({},{$unset: {pi: 1}}) 多重记录 db.getCollection(“用户数据”)。更新({},{$unset: {pi: 1}}, {multi: true})

PyMongo (Python mongo)的解决方案:

db.example.update({}, {'$unset': {'tags.words':1}}, multi=True);

要引用一个包并删除各种“键”, 试试这个

db['name1.name2.name3.Properties'].remove([
{
     "key" : "name_key1"
},
{
     "key" : "name_key2"
},
{
     "key" : "name_key3"
}
)]

检查“words”是否存在,然后从文档中删除

    db.users.update({"tags.words" :{$exists: true}},
                                           {$unset:{"tags.words":1}},false,true);

True表示匹配时更新多个文档。