Delete an object from a nested Document in mongoose

Viewed 22

I need to delete an object from an array of objects in mongoose.In the below example I need to delete a particular dish from an array of dishes.These array of dishes will be there inside array of categories This dish object has to be deleted:

 {
                "dishName": "Dosa Cooks",
                "dishType": "Veg",
                "dishDescription": "A dosa is a thin batter-based dish originating from South India, made from a fermented batter predominantly consisting of lentils and rice.",
                "dishPrice": "45",
                "dishAvailability": true,
                "dishImage": "Image",
                "_id": "62f3ddf232bfba6253efbe85"
            },

The main json present in mongo:

{
"_id": "62f3ddf232bfba6253efbe83",
"restaurantName": "Dhanush Cafe",
"restaurantId": "RESTN2500005",
"mobileNumber": "999809095",
"restaurantDishes": [
    {
        "category": "Tiffin",
        "dishes": [
            {
                "dishName": "Dosa Cooks",
                "dishType": "Veg",
                "dishDescription": "A dosa is a thin batter-based dish originating from South India, made from a fermented batter predominantly consisting of lentils and rice.",
                "dishPrice": "45",
                "dishAvailability": true,
                "dishImage": "Image",
                "_id": "62f3ddf232bfba6253efbe85"
            },
            {
                "dishName": "Idli",
                "dishType": "Veg",
                "dishDescription": "Idli or idly is a type of savoury rice cake, originating from the Indian subcontinent, popular as breakfast foods in Eastern and Southern India and in Sri Lanka.",
                "dishPrice": "30",
                "dishAvailability": true,
                "dishImage": "Image",
                "_id": "62f3ddf232bfba6253efbe86"
            }
        ],
        "_id": "62f3ddf232bfba6253efbe84"
    },
    {
        "category": "Drinks",
        "dishes": [
            {
                "dishName": "Tea",
                "dishType": "Veg",
                "dishDescription": "Tea is an aromatic beverage prepared by pouring hot or boiling water over cured or fresh leaves of Camellia sinensis",
                "dishPrice": "25",
                "dishAvailability": true,
                "dishImage": "Image",
                "_id": "62f3ddf232bfba6253efbe88"
            },
            {
                "dishName": "Coffee",
                "dishType": "Veg",
                "dishDescription": "Coffee is a brewed drink prepared from roasted coffee beans, the seeds of berries from certain flowering plants in the Coffea genus.",
                "dishPrice": "30",
                "dishAvailability": true,
                "dishImage": "Image",
                "_id": "62f3ddf232bfba6253efbe89"
            }
        ],
        "_id": "62f3ddf232bfba6253efbe87"
    }
],
"createdAt": "2022-08-10T16:33:54.733Z",
"updatedAt": "2022-08-10T17:03:24.902Z",
"__v": 0

}

0 Answers
Related