[CSHARP-588] Strong typed generic functions for inner document updates Created: 04/Oct/12  Updated: 20/Mar/14  Resolved: 13/Mar/13

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.6
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Nikita Sushkov Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: driver, update
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-531 Support the $ positional operator whe... Closed

 Description   

Hi
I've tried to perform an update of embedded document using new generic syntax, but didn't find any solution (only adding and deleting embedded documents in collections). I meen code like this:

MongoCollection.Update(
Query.And(Query<ReadDto.Concert>.EQ(ev => ev.Id, evnt.AggregateId),
Query<ReadDto.Concert>.ElemMatch(item => item.LineupItems,
builder =>
builder.EQ(
item => item.ArtistId,
evnt.EntityObjectId))),
Update.Set("LineupItems.$.Headliner", evnt.Headliner)
.Set("ChangeDate", evnt.ChangeDate)
.Set("Version", evnt.Version));

Is it possible to construct such update using Update<>? And also it's not clear how to perform an update of embedded document which is single.



 Comments   
Comment by Craig Wilson [ 04/Oct/12 ]

We are still working out how to get the $ syntax to work in a typed situation. It's a very difficult problem and you are stuck using strings right now when needing the $ positional operator. TFor the other properties, "ChangeDate" and "Version", you can use the typed version and combine it with the non-typed version using the combine method.

var update = Update.Combine(
Update.Set("LineupItems.$.Headliner", evnt.Headliner),
Update<ReadDto.Concert>.Set(v => v.ChangeDate, evnt.ChangeDate),
Update<ReadDto.Concert>.Set(v => v.Version, evnt.Version));

Generated at Wed Feb 07 21:37:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.