I have a MongoDB Document as follows
{
"_id" : ObjectId("5a55775cbd12982cc063c71a"),
"ShipmentNumber" : "00004000000048652254",
"Cartons" : [
{
"_id" : ObjectId("5a5575bcbd12982cc063b718"),
"CartonNumber" : "0076013926580S",
"Skus" : [
{
"_id" : ObjectId("5a5575bcbd12982cc063b719"),
"SkuNumber" : "06577647",
"ShippedQuantity" : 12,
},
{
"_id" : ObjectId("5a5575bcbd12982cc063b519"),
"SkuNumber" : "06577657",
"ShippedQuantity" : 15,
}
],
"IsScanned" : false,
},
}
How can I update the "ShippedQuantity" for a particular Sku element based on its "_id" in C# code ?
I tried something like below. But it is not working. Getting error message like
cannot use the part (Cartons of Cartons.$[].Skus.$.ShippedQuantity) to traverse the element
var filter = Builders<BsonDocument>.Filter.Eq("Cartons.Skus._id", new ObjectId("5a5575bcbd12982cc063b519"));
var update = Builders<BsonDocument>.Update.Set("Cartons.$[].Skus.$.ShippedQuantity", 50)
I am facing difficulties when I try to update multi level documents. (In this case I have a list of Cartons and each carton will have its own list of skus and I need to update a specific sku's element)
Please provide a solution or alternative approach to update this inner level (more than 2 levels) documents in MongoDB using C#.
I updated my MongoDB server to the latest 3.6.1. But that is also not helping.
Thanks for your help.