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

Inconsistent response from AsQueryable().FirstOrDefaultAsync

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.2.4
    • Affects Version/s: 2.2.3
    • Component/s: API, Linq
    • Labels:
      None
    • Environment:
      Ubuntu Linux

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

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            js Jonathan Sisam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: