{ 
    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)

您也可以使用3.4中的project在聚合中实现这一点

{$项目:{"标签。0}}

要删除一个字段,您可以使用这个命令(这将应用于集合中的所有文档):

db.getCollection('example').update({}, {$unset: {Words:1}}, {multi: true});

在一个命令中删除多个字段:

db.getCollection('example').update({}, {$unset: {Words:1 ,Sentences:1}}, {multi: true});

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

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

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

{ 名称:“书”, 标签:{ 词:[' abc ', ' 123 '), 纬度:33岁 长:22 } }

Ans:

db.tablename.remove ({tags.words: [' abc ', ' 123 ']})