【问题标题】:mongodb remove array from the collection using index or any methodmongodb 使用索引或任何方法从集合中删除数组
【发布时间】:2022-02-24 19:54:09
【问题描述】:

我有以下收藏:

我使用以下代码来删除 orderList 数组中与 orderId 匹配的元素。但它不起作用。

Order.update({"_id":ObjectId(userOrder._id)},{"$pull":{"orderList":{orderId:"WPN-1645691337205"}}});

我也尝试了以下代码

Order.update({"_id:":ObjectId("621741dcd40da387489093c2")}, {$unset : {"orderList.0" : 1 }});

Order.update({"_id:":ObjectId("621741dcd40da387489093c2")}, {$pull:{"orderList":null}});

谢谢, 乔

【问题讨论】:

    标签: mongodb express


    【解决方案1】:

    试试这个:

    Order.update(
      { _id: ObjectId(userOrder._id)},
      { $pull: { orderList: { orderId: "WPN-1645691337205" } } },
      function(error, response) {}
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 2015-09-06
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多