[CSHARP-531] Support the $ positional operator when building a query for updating a collection Created: 18/Jul/12  Updated: 30/Mar/18  Resolved: 09/Mar/15

Status: Closed
Project: C# Driver
Component/s: Feature Request
Affects Version/s: 1.5
Fix Version/s: 2.0

Type: New Feature Priority: Major - P3
Reporter: Seb Michaud Assignee: Unassigned
Resolution: Done Votes: 18
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-588 Strong typed generic functions for in... Closed
is duplicated by CSHARP-1046 Type-safe $set with positional operat... Closed
Related

 Description   

The feature to add strongly typed LINQ support to the builders doesn't suppport updating of nested collections.

For example, it's possible to write an update like:

statusCollection.Update(
Query<StatusGroup>.Where(sg => sg.Statuses.Any(s => s.Id == status.Id)),
Update.Set("Statuses.$.UpdateTime", DateTime.Now)
.Set("Statuses.$.Name", "name")
);

It would be nice if it was possible to write something like:

statusCollection.Update(
Query<StatusGroup>.Where(sg => sg.Statuses.Any(s => s.Id == status.Id)),
Update<StatusGroup, Status>.Set(sg => sg.Statuses, s => s.UpdateTime, DateTime.Now)
.Set(sg => sg.Statuses, s => s.Name, "name")
);

Eventually it would be nice to support multi-level nested collections but that might be dependant on https://jira.mongodb.org/browse/SERVER-831



 Comments   
Comment by Sami Ayari [ 30/Mar/18 ]

Do you plan to add support for the $[ ] array operator?

Comment by Craig Wilson [ 09/Mar/15 ]

This is only applicable to the new API in 2.0.0. -1 can be used as an indexer or with GetElementAt to indicate to us to use the positional operator. For example:

Builders<Entity>.Update.Set(x => x.MyArray[-1].Value, 10);
// will yield {$set: { "MyArray.$.Value", 10 } }

Comment by Craig Wilson [ 09/Mar/15 ]

Git commit: https://github.com/mongodb/mongo-csharp-driver/commit/ecbd337d0a0f8cf63258251de75425f99277a97b

Comment by Fras Faisal [X] [ 24/Dec/14 ]

yes , this is one of the most important points , because every change in fields name must be easily detected during compile time

thanks for MongoDB staff

Comment by Craig Wilson [ 22/Jul/13 ]

We have not begun this feature. If it is important to you, please vote it up.

Comment by David Pfeffer [ 22/Jul/13 ]

Just wondering - any progress on this issue? Hit into this problem today.

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