I have a MongoDB Collection of Documents that has an imbedded collection of documents as an array. I want to find and update a specific member of that array if certain values exist in the array member document.
I can find the array member without issue(the Query Document works perfectly), but when I try to $set the member with the new/updated values, the first member is always set, rather than the member that I found.
How can I update the same array member that I found, rather than the first item in the array. Here is what I am currently doing, where 'InventoryData' is the name of the embedded array, and the InventoryRecord is the updated member that contains the value my query is matching on successfully:
Here is the query that successfully finds the matching array member:
query = new QueryDocument { { "_id", BTKey }, { "InventoryData.WarehouseCode", InventoryRecord.WarehouseCode }, { "InventoryData.InventoryType", InventoryRecord.InventoryType }, { "InventoryData.CustomerNumber", InventoryRecord.CustomerNumber }
Then, here is where I try to update that member using .$ :
var update2 = MongoDB.Driver.Builders.Update.Set("InventoryData.$", InventoryRecord.ToBsonDocument());
MongoConnection.Products.Update(query, update2, UpdateFlags.None);
...but the first item in the array is always updated, rather than the target item.
Any help will be greatly appreciated, thanks.