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

Allow string or regular expressions in values for $in with string

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.16.0
    • 2.4.3
    • Linq, LINQ3
    • using mongo csharp driver 2.4.3

    Description

      When trying to parse the following query:

      var f = Builders<collectionFoo>.Filter;
      var query = f.In("product", some.Products)
                          & f.Gte("version", "1.0.0")
                          & f.In("version", new List<BsonRegularExpression>() { new BsonRegularExpression("/^1.2.0/"), new BsonRegularExpression("/^1.1.3/")  });
      

      another ways

      new BsonArray(some.versions.Select(x => new BsonRegularExpression(x)))
      new BsonArray(some.versions.Select(x => new RegEx(x)))
      

      I wanted the following results.

      { "$match" : { "product" : { "$in" : [1, 2, 3, 4] }, "version" : { "$gte" : "1.0.0", "$in" : [/^1.2.0/, /^1.1.3/, .... ] }
      

      But the result is ...

      { "$match" : { "product" : { "$in" : [1, 2, 3, 4] }, "version" : { "$gte" : "1.0.0", "$in" : ["/^1.2.0/", "/^1.1.3/", ....] }
      

      using BsonRegularExpression in `$in` command

      https://docs.mongodb.com/manual/reference/operator/query/in/
      The $in operator can specify matching values using regular expressions of the form /pattern/. You cannot use $regex operator expressions inside an $in.

      I want to use regex in '$in' command..

      Attachments

        Activity

          People

            robert@mongodb.com Robert Stam
            Ssemi Ssemi Seol
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: