Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-493

LINQ - Allow Regex Usage inside $all

    Details

      Description

      There appears to be no LINQ way to perform the following Mongo query:

      db.Collection.find({field : {$all : [ /^a/, /^d/]}})

      One possible suggestion to implement this is to create a ContainsAll overload that receives Regex parameters.

        Issue Links

          Activity

          • Comments
          Hide
          zaidmasud Zaid Masud added a comment - - edited

          This is a bit of a tangent to the specific issue reported here, but one thing we have seen with these custom extension methods is that unit testing becomes difficult. So for example, if our unit tests are using in-memory objects then ContainsAll won't work.

          Here are two alternatives to ContainsAll using standard LINQ/.NET framework:

          1) Support IsSubsetOf on two HashSets – this is the most natural C# interpretation of ContainsAll ... $all is really a Subset predicate.
          2) Support !myValues.Except(collection.Array).Any() as a $all implementation

          Of course neither would support regexes, so perhaps ContainsAll will still be needed for Regexes on $all.

          Show
          zaidmasud Zaid Masud added a comment - - edited This is a bit of a tangent to the specific issue reported here, but one thing we have seen with these custom extension methods is that unit testing becomes difficult. So for example, if our unit tests are using in-memory objects then ContainsAll won't work. Here are two alternatives to ContainsAll using standard LINQ/.NET framework: 1) Support IsSubsetOf on two HashSets – this is the most natural C# interpretation of ContainsAll ... $all is really a Subset predicate. 2) Support !myValues.Except(collection.Array).Any() as a $all implementation Of course neither would support regexes, so perhaps ContainsAll will still be needed for Regexes on $all.

            People

            • Assignee:
              Unassigned
              Reporter:
              zaidmasud Zaid Masud
              Participants:
              Last commenter:
              Barrie Segal
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since reply:
                3 years, 10 weeks, 6 days ago