[CSHARP-4813] Verify more carefully that property named Count is a collection property Created: 17/Oct/23  Updated: 07/Dec/23  Resolved: 07/Dec/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.22.0
Fix Version/s: 2.23.0

Type: Bug Priority: Blocker - P1
Reporter: Markus Wildgruber Assignee: Robert Stam
Resolution: Fixed Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

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?


 Description   

Summary

When having a property of type long named Count, the translation of a Linq-query with greater than fails.

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

How to Reproduce

Test document:

        [BsonIgnoreExtraElements]
        public class TestDoc
        {
            public long Count { get; set; }
        }

Code: 

            var settings = MongoClientSettings.FromConnectionString("mongodb://localhost");
            settings.LinqProvider = MongoDB.Driver.Linq.LinqProvider.V3;
            var client = new MongoClient(settings);
            var db = client.GetDatabase("test");
            var coll = db.GetCollection<TestDoc>("long_count_fail");
            var doc = new TestDoc() { Count = 123 };
            await coll.InsertOneAsync(doc);
            var countGreaterThanZero = coll.AsQueryable().Where(x => x.Count > 0).ToList();
            Console.WriteLine(countGreaterThanZero.Count);  // 0 – failure
            var countEquals123 = coll.AsQueryable().Where(x => x.Count == 123).ToList();
            Console.WriteLine(countEquals123.Count);  // >= 1 – works

Additional Background

In Version 2,20.0 of the driver, the failure could not be observed, a change in v2.22.0 is suspected to cause the error.



 Comments   
Comment by Githook User [ 07/Dec/23 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4813: Verify more carefully that property named Count is a collection method.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/8365a619214cfcf67659f5d647435654c8e3c1ef

Comment by Markus Wildgruber [ 18/Oct/23 ]

robert@mongodb.com thank you for the quick response

Comment by Robert Stam [ 17/Oct/23 ]

Thanks for reporting this. I am able to reproduce it and am working on a fix.

Comment by PM Bot [ 17/Oct/23 ]

Hi m.wildgruber@sevantage.de, thank you for reporting this issue! The team will look into it and get back to you soon.

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