これを試して :
db.shop.update({}, {"$pull": {"products": {"amount": 0} }},false,true);
update
ドキュメントからの抜粋:
db.collection.update( criteria, objNew, upsert, multi )
したがって、ここではupsert = false、multi=trueが必要です。理由:一致基準はすべて一致することを意味します。したがって、更新ステートメントは最初の行を一致させた後に終了し、何もしません。一致するすべての行を変更するには、フラグをtrueとして指定{}
する必要があります。multi
例:
> db.newColl.find()
{ "_id" : ObjectId("500d262db869eab21b7fc6b0"), "products" : [ ] }
{ "_id" : ObjectId("500d2632b869eab21b7fc6b1"), "products" : [ { "amount" : 5, "id" : "9647562" } ] }
>
>
> db.newColl.update({},{"$pull": {"products": {"amount": 5 } }});
> db.newColl.find()
{ "_id" : ObjectId("500d262db869eab21b7fc6b0"), "products" : [ ] }
{ "_id" : ObjectId("500d2632b869eab21b7fc6b1"), "products" : [ { "amount" : 5, "id" : "9647562" } ] }
>
>
> db.newColl.update({},{"$pull": {"products": {"amount": 5 } }},false,true);
> db.newColl.find()
{ "_id" : ObjectId("500d2622b869eab21b7fc6ae"), "products" : [ ] }
{ "_id" : ObjectId("500d2632b869eab21b7fc6b1"), "products" : [ ] }