[CSHARP-2801] Nested .Any() behavior changed in 2.8.0 Created: 21/Oct/19  Updated: 28/Oct/23  Resolved: 06/Nov/19

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: None
Fix Version/s: 2.9.3

Type: Bug Priority: Major - P3
Reporter: Alex Bevilacqua Assignee: Dmitry Lukyanov (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-2744 Consider to restore(or modify) the pr... Closed
Case:

 Description   

Given the follow

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
    }
  }
}



 Comments   
Comment by Githook User [ 06/Nov/19 ]

Author:

{'username': 'DmitryLukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'name': 'Dmitry Lukyanov'}

Message: CSHARP-2801: Nested .Any() behavior changed in 2.8.0.
Branch: v2.9.x
https://github.com/mongodb/mongo-csharp-driver/commit/e856650f8d0afa148799cc20ffabf0678bce2b6a

Comment by Githook User [ 06/Nov/19 ]

Author:

{'username': 'DmitryLukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'name': 'Dmitry Lukyanov'}

Message: CSHARP-2801: Nested .Any() behavior changed in 2.8.0.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/fc8f9265013a227764059dfaafc5fcc36fdc7ca5

Generated at Wed Feb 07 21:43:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.