meal plan updation/ updating object fileds insided array in mongodb

PHOTO EMBED

Fri Apr 05 2024 10:03:33 GMT+0000 (Coordinated Universal Time)

Saved by @CodeWithSachin #aggregation #mongodb #arrayfilter #array

db.participantDietMealPlanDetails.updateMany({
    "mealPlan.dishVariation": "Milkshake",
	"_id":ObjectId("60d4258c4adb9a4b6fe4d99b")
},
    {
    $set: {
        "mealPlan.$[elem].dishVariation": "Milkshake",
        "mealPlan.$[elem].dishVariationId":  "660ea659e1645e032a289770",
        "mealPlan.$[elem].sizes": [{
                "calories": {
                    "value": "184",
                    "unit": "kcal"
                },
                "cookedWeight": "200",
                "name": "Medium Glass",
                "fat": {
                    "value": "5.0",
                    "unit": "gms"
                },
                "calcium": {
                    "value": "0.0",
                    "unit": "mg"
                },
                "iron": {
                    "value": "0.0",
                    "unit": "mg"
                },
                "fibre": {
                    "value": "0.0",
                    "unit": "mg"
                },
                "sodium": {
                    "value": "0.0",
                    "unit": "mg"
                },
                "sugars": {
                    "value": "0.0",
                    "unit": "mg"
                },
                "protein": {
                    "value": "4.7",
                    "unit": "gms"
                },
                "carbs": {
                    "value": "30.4",
                    "unit": "gms"
                }
            }
        ]

    }
}, {
    arrayFilters: [{
            "elem.dishVariation": "Milkshake"
        }
    ]
})
content_copyCOPY