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

Count comparison with constant on the left is not translated correctly

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.23.0
    • Affects Version/s: 2.22.0
    • Component/s: None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      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?

      Show
      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?

      Summary

      Linq query to check collection items count is not correctly translate to mongo aggregate pipeline.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      MongoDB.Driver 2.22.0

      How to Reproduce

      public class Document
      {
          public HashSet<string> Tokens { get; set; } = new();
      }
      
      public void CheckTokensCountQuery()
      {
          var collection = Database.GetCollection<Document>("test");
          var query = collection
              .AsQueryable()
              .Where(x => 1 < x.Tokens.Count);
      
          var queryString = query.ToString();
      
          // queryString is:
          // test.test.Aggregate([{ "$match" : { "Tokens.0" : { "$exists" : false } } }])
      }
      

      As you can see above, `queryString` doesn't actually check that the size of the `Tokens` collection is greater than 1. Instead, it checks that the `Tokens` collection is empty.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            exomicky53@gmail.com Mikhail Khalizev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: