Remove element from nested array mongodb

前端 未结 2 1591
时光说笑
时光说笑 2020-12-12 03:16

i have the following document , it has two array\'s , one inside the other ,
attachment array and files array inside attachment array . i want to delete an element insi

2条回答
  •  情书的邮戳
    2020-12-12 03:24

    You can try below update query in 3.6 version.

    Invoice.update( 
     {}, 
     {"$pull":{"attachment.$[].files":{_id:ObjectId("5b7969ac8fb15f3e5c8e844e")}}}, 
     {"multi": true}, function (err, result) {console.log(result);
    });
    

    Use db.adminCommand( { setFeatureCompatibilityVersion: 3.6 or 4.0 depending on your version } ) if your are upgrading from old version.

提交回复
热议问题