[CSHARP-1645] Inconsistent response from AsQueryable().FirstOrDefaultAsync Created: 02/May/16  Updated: 01/Jun/16  Resolved: 03/May/16

Status: Closed
Project: C# Driver
Component/s: API, Linq
Affects Version/s: 2.2.3
Fix Version/s: 2.2.4

Type: Bug Priority: Minor - P4
Reporter: Jonathan Sisam Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu Linux



 Description   

Hi

I get inconstant results from MyCollection.AsQueryable().FirstOrDefaultAsync(...)

while MyCollection.Find(...).FirstOrDefaultAsync() works fine.

For example:

Given the following test

        public class TestObject
        {
            [BsonId]
            public string DeviceID { get; set; }
            public List<string> Sessions = new List<string>();
        }
 
 async private void demo(theTestModel model)
        {
            var id = "heavy";
            var test = model.Database.GetCollection<TestObject>("test");
            model.Database.DropCollection(test.CollectionNamespace.CollectionName);
            var heavy = new TestObject() { DeviceID = "heavy" };
            var lite = new TestObject() { DeviceID = "light" };
            for (int i = 0; i < 260000; i++) heavy.Sessions.Add(Guid.NewGuid().ToString());
            for (int i = 0; i < 1000; i++) lite.Sessions.Add(Guid.NewGuid().ToString());
            test.InsertOne(heavy);
            test.InsertOne(lite);
 
            
            var test1heavy = await test.Find(x => x.DeviceID == id).FirstOrDefaultAsync();
            // test1heavy contains the expected results
 
            var test2heavy = await test.AsQueryable().FirstOrDefaultAsync(x => x.DeviceID == id);
            // test2heavy is null
            id = "light";
 
            // test1light contains the expected results
            var test1light = await test.Find(x => x.DeviceID == id).FirstOrDefaultAsync();
            // test2light contains the expected results
            var test2light = await test.AsQueryable().FirstOrDefaultAsync(x => x.DeviceID == id);
 
            
        }



 Comments   
Comment by Jonathan Sisam [ 10/May/16 ]

Thanks

Comment by Githook User [ 03/May/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1645: fixed issue with empty first batches.
Branch: v2.2.x
https://github.com/mongodb/mongo-csharp-driver/commit/1a6f08fc09a30ac68239171e384c93a73323a3b8

Comment by Githook User [ 03/May/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1645: fixed issue with empty first batches.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/c94dc1bb0acac63381df1ca5135fdecfdedb30bf

Comment by Craig Wilson [ 02/May/16 ]

Hi Jonathan,

Thanks for the report and easy reproduction step. I have reproduced this and am trying to figure out what is going on and how to fix it.

Craig

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