Deleting a nested array object by comparing two conditions

Viewed 47

I want to delete an object from a nested array by comparing another field in the Mongo database by using mongoose in javascript. Here is my schema.

{
    "userId": "5e80e3021c5c461433807173",
    "selected": [
      {
        "productId": "5e80e664602315159a2959da",
        "selectedQty": 1,
        "isAvailable": true,
        "name": "Nike Mountain Shoe",
        "category": "Shoes",
        "qty": 2497,
        "price": 1500,
        "imageUrl": "aHR0cHM6Ly93d3cucmFua2FuZHN0eWxlLmNvbS9tZWRpYS9wcm9kdWN0cy9qL2phbWVzLXBlcnNlLWxvbmctc2xlZXZlLXQtc2hpcnQtbWVucy1sb25nLXNsZWUuanBn"
      },
      {
        "productId": "5e80e4893db96d14947dce80",
        "selectedQty": 1,
        "isAvailable": false,
        "name": "Blimper Men Shoe",
        "category": "Shoes",
        "qty": 2497,
        "price": 500,
        "imageUrl": "aHR0cHM6Ly93d3cucmFua2FuZHN0eWxlLmNvbS9tZWRpYS9wcm9kdWN0cy9qL2phbWVzLXBlcnNlLWxvbmctc2xlZXZlLXQtc2hpcnQtbWVucy1sb25nLXNsZWUuanBn"
      }
    ]
  }

How can I delete a product by comparing userId and productId?

0 Answers
Related