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

The queryable interface no longer supports slicing via Take

    • Type: Icon: Question Question
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.0
    • Component/s: None
    • None
    • None
    • Dotnet Drivers
    • Hide

      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?

      Show
      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?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      As of c# driver 3.2.0, using the "Take" operator to perform a slice when querying via the queryable interface no longer works.

      How to Reproduce

      See attached for a minimal console app that reproduces the behavior. Notable lines:

      widgetBoxCollection.InsertOne(new WidgetBox([new Widget("A"), new Widget("B"), new Widget("C")]));
      
      var lastTwoWidgets = await widgetBoxCollection.AsQueryable()
      .Where(_ => true)
      .SelectMany(j => j.Widgets.Take(-2))
      .ToListAsync();
      
      var lastTwoWidgets2 = (await widgetBoxCollection.AsQueryable()
      .Where(_ => true)
      .Select(j => j.Widgets.Take(-2))
      .ToListAsync()).Single();
      
      Console.WriteLine($"Widgets result 1: [{string.Join(",", lastTwoWidgets.Select(w => w.Name))}]");
      Console.WriteLine($"Widgets result 2: [{string.Join(",", lastTwoWidgets2.Select(w => w.Name))}]");
      

      Output on 3.1.0:

      Widgets result 1: [B,C]
      Widgets result 2: [B,C]
      

      Output on 3.2.0:

      Widgets result 1: []
      Widgets result 2: []
      

        1. Program.cs
          1.0 kB
          Mirek Kukla

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            mirek@rynly.com Mirek Kukla
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None