[CSHARP-4607] Support $all filters with more Contains methods Created: 09/Apr/23  Updated: 28/Oct/23  Resolved: 20/Apr/23

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: 2.19.1
Fix Version/s: 2.19.2

Type: Bug Priority: Unknown
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Case:
Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

The following pattern:

 

values.All(e => document.A.Contains(e)) // where values is a constant array

is translated to the filter:

 

 

{ A : { $all : [<values>] } }

This is true of both LINQ2 and LINQ3.

 

However, LINQ3 currently only supports this pattern if the Contains method resolves to Enumerable.Contains. We need to support other Contains methods, for example ICollection.Contains.

Instead of looking for specific Contains methods (there are many), we can see if the Contains method "looks" like a Contains method:

  1. Is named "Contains"
  2. Return type is bool
  3. Has two parameters (call them source and value)
  4. Source implements IEnumerable<TItem>
  5. value is assignable to TItem

The Contains method could be either a static or an instance method:

  • if static, source is the first argument and value is the second
  • if instance, source is the object itself and value is the only argument


 Comments   
Comment by Githook User [ 18/May/23 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4607: Support $all filters with more Contains methods.
Branch: v2.19.x
https://github.com/mongodb/mongo-csharp-driver/commit/c20033d7254fb00cfd2a7fb477ade34c6017becd

Comment by Githook User [ 20/Apr/23 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4607: Support $all filters with more Contains methods.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/29b57bf39fed671da8d09f3ad51537b497af948e

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