[CSHARP-2232] Add Support for $[] array operator Created: 30/Mar/18  Updated: 11/Apr/22  Resolved: 11/Apr/22

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

Type: New Feature Priority: Major - P3
Reporter: Sami Ayari Assignee: Unassigned
Resolution: Duplicate Votes: 7
Labels: rfw
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-4079 Implement positional update operators... Closed

 Comments   
Comment by James Kovacs [ 11/Apr/22 ]

We have implemented support for $[] in CSHARP-4079. It will be included in the upcoming 2.16.0 release.

Comment by Robert Stam [ 28/Jan/21 ]

 We are refactoring our LINQ implementation and will look at including support for this.

Comment by alexov inbox [ 26/Jan/21 ]

plz add this future i think its fast 

Comment by Christos Sakellarios [ 21/Apr/20 ]

Is there any progress on this?

Comment by Wan Bachtiar [ 29/Jan/19 ]

Hi Sami,

Thanks for opening the feature request.

The LINQ support for the all positional operator $[] is indeed missing.

For a workaround, you can use the the non-typed operator in the mean time. For example, given the following documents:

{"_id" : 1, "grades" : [
      { "grade" : 80, "mean" : 75, "std" : 8 },
      { "grade" : 85, "mean" : 90, "std" : 6 },
      { "grade" : 85, "mean" : 85, "std" : 8 }]
},
{"_id" : 2, "grades" : [
      { "grade" : 90, "mean" : 75, "std" : 8 },
      { "grade" : 87, "mean" : 90, "std" : 5 },
      { "grade" : 85, "mean" : 85, "std" : 6 }]
}

To perform the equivalent update operation as below:

db.collection.update( { }, { "$inc": { "grades.$[].std" : -2 } }, { "multi": true } )

You can do:

    var filter = new BsonDocument();
    var update = Builders<BsonDocument>.Update.Inc("grades.$[].std", -2);
    var document = collection.UpdateMany(filter, update);     

Regards,
Wan.

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