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

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

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.16.0
    • Affects Version/s: 2.4.3
    • Component/s: Linq, LINQ3
    • Environment:
      using mongo csharp driver 2.4.3

      When trying to parse the following query:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      new BsonArray(some.versions.Select(x => new BsonRegularExpression(x)))
      new BsonArray(some.versions.Select(x => new RegEx(x)))
      

      I wanted the following results.

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      { "$match" : { "product" : { "$in" : [1, 2, 3, 4] }, "version" : { "$gte" : "1.0.0", "$in" : [/^1.2.0/, /^1.1.3/, .... ] }
      

      But the result is ...

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      { "$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..

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

              Created:
              Updated:
              Resolved: