-
Type: Bug
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: 2.22.0
-
Component/s: None
-
None
-
Fully Compatible
-
Not Needed
-
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.