[英]How to remove a property from document - mongo / loopback
I have an old property on one of my models, and I'd like to remove it from all the documents in a collection. 我的一个模型中有一个旧属性,我想将其从集合中的所有文档中删除。 I've tried posting via /upsertWithWhere using the id to update by:
我尝试通过/ upsertWithWhere发布,其中使用ID来更新:
I also was thinking I could do a regular POST and just overwrite each document, but these particular documents are large and I'd rather not do that. 我还认为我可以执行常规的POST并只覆盖每个文档,但是这些特定的文档很大,因此我不愿意这样做。
Is there a way to simply patch it? 有没有办法简单地修补它?
Edit: Need an answer that implements this Via the Loopback API. 编辑:需要一个通过Loopback API实现此目的的答案。
This query should do the trick: 这个查询应该可以解决这个问题:
db.collection('collection_name').update({},{$unset: {"old_property": ""}}, {multi:true})
Obviously, just make sure you insert into "old_property" the field name of that old property. 显然,只需确保将“旧属性”的字段名称插入“ old_property”即可。
Explaining the query a little further... 进一步解释查询...
Used this as a reference: https://docs.mongodb.com/manual/reference/method/db.collection.update/#multi-parameter 将此用作参考: https : //docs.mongodb.com/manual/reference/method/db.collection.update/#multi-parameter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.