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

Nested .Any() behavior changed in 2.8.0

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.9.3
    • Affects Version/s: None
    • Component/s: Linq
    • None

      Given the follow

      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
      public class Thing
      {
          public List<Product> Products { get; set; }
      }
      public class MechanicalClaim
      {
          public string AuthNumber { get; set; }
      }
      public class Product
      {
          public List<MechanicalClaim> MechanicalClaims { get; set; }
      }
      [TestClass]
      public class UnitTest1
      {
        // no assertions; just set slowms: 0 on mongod to view query shape
        [TestMethod]
        public void GenerateQueryForNestedAny()
        {
            var client = new MongoClient("mongodb://localhost");
            var _collection = client.GetDatabase("test").GetCollection<Thing>("thing");
            var _contractAuth = _collection.Find(
                x => x.Products != null && x.Products.Any(
                    p => p.MechanicalClaims != null && p.MechanicalClaims.Any(
                        m => m.AuthNumber.StartsWith("test")
                    )
                )
            ).FirstOrDefault();
        }
      }
      

      C# Driver 2.7.3

      2019-10-21T09:55:35.385-0400 I NETWORK  [conn15] received client metadata from 127.0.0.1:61429 conn15: { driver: { name: "mongo-csharp-driver", version: "2.7.3.0" }, os: { type: "Windows", name: "Microsoft Windows 10.0.18362", architecture: "x86_64", version: "10.0.18362" }, platform: ".NET Core 4.6.28008.02" }
      2019-10-21T09:55:35.417-0400 I COMMAND  [conn15] command test.thing command: find { find: "thing", filter: { Products: { $ne: null, $elemMatch: { MechanicalClaims: { $ne: null }, MechanicalClaims.AuthNumber: /^test/s } } }, limit: 1, $db: "test", lsid: { id: UUID("501ca24f-3833-4dd9-b578-5c2c7afc90e8") } } planSummary: EOF keysExamined:0 docsExamined:0 cursorExhausted:1 numYields:0 nreturned:0 reslen:99 locks:{ Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_msg 0ms
      

      Query Shape

      {
        Products: {
          $ne: null,
          $elemMatch: {
            MechanicalClaims: { $ne: null },
            MechanicalClaims.AuthNumber: /^test/s
          }
        }
      } 
      

      C# Driver 2.8.0

      2019-10-21T09:57:34.116-0400 I NETWORK  [conn17] received client metadata from 127.0.0.1:61482 conn17: { driver: { name: "mongo-csharp-driver", version: "2.8.0.0" }, os: { type: "Windows", name: "Microsoft Windows 10.0.18362", architecture: "x86_64", version: "10.0.18362" }, platform: ".NET Core 4.6.28008.02" }
      2019-10-21T09:57:34.148-0400 I COMMAND  [conn17] command test.thing command: find { find: "thing", filter: { Products: { $ne: null, $elemMatch: { MechanicalClaims: { $ne: null }, AuthNumber: /^test/s } } }, limit: 1, $db: "test", lsid: { id: UUID("d335de48-d269-49d7-bb52-0aab9384af67") } } planSummary: EOF keysExamined:0 docsExamined:0 cursorExhausted:1 numYields:0 nreturned:0 reslen:99 locks:{ Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_msg 0ms
      

      Query Shape:

      {
        Products: {
          $ne: null,
          $elemMatch: {  
            MechanicalClaims: { $ne: null },
            AuthNumber: /^test/s
          }
        }
      }
      

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: