I have a collection of documents in MongoDB with a structure like this (there are several container documents, each of which contains Sessions , each session contains 1 order, each order contains several elements):
{ "Sessions" : [{ "ID" : "1882a092-d395-45d1-b36b-e2fa3df81b95", "Order" : { "Items" : [{ "_id" : "a9c94a5e-10ef-433d-9c63-f4555eb7c2a7", "Title" : "UPDATE THIS", }] } }], "_id" : "1b640bc4-fdb4-49b1-9c60-e4c6f1bd0405" }
I would like to update the Title this Item within the order in the session, knowing the _id item (I also know the session identifier if this helps):
I tried the following:
col.Update(Query.EQ("Sessions.ID", sessionID), Update.Set("Sessions.$.Order.Items.Title", newTitle)); col.Update(Query.EQ("Sessions.Order.Items._id", id), Update.Set("Sessions.Order.Items.$.Title", newTitle));
Both throw an exception WriteConcern detected an error 'cannot use the part (Sessions of Sessions.Order.Items.0.Status) to traverse the element ... I also tried different combinations of combined queries using Query.And , which probably make so little sense that they should not be published here.
How to update a field in a sub-folder contained in an array of documents using a C # driver?
I understand that this cannot be done only with the help of the positioning operator (and the positioning operator will not magically match the internal array).
I am looking from ready-made solutions how to perform this type of update without changing the scheme.
Marek source share