[CSHARP-4700] LINQ3 OrderBy Count() fails Created: 30/Jun/23  Updated: 28/Oct/23  Resolved: 04/Jul/23

Status: Closed
Project: C# Driver
Component/s: Linq, LINQ3
Affects Version/s: 2.20.0
Fix Version/s: 2.21.0

Type: Bug Priority: Unknown
Reporter: Janis Zinn Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: Count, LINQ, LINQ3, Linq, groupby, linq, linq,query, orderby
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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

Hi,

when i try to GroupBy() ,then OrderBy(Count()) i get a MongoDB.Driver.MongoCommandException: Command aggregate failed: PlanExecutor error during aggregation :: caused by :: The argument to $size must be an array, but was of type: missing.'

How to Reproduce

class Example {
 string Name
}
 
Collection
.AsQueryable()
.GroupBy(x => x.Name)
.OrderBy(x => x.Count())

MongoDB.Driver.MongoCommandException: 'Command aggregate failed: PlanExecutor error during aggregation :: caused by :: The argument to $size must be an array, but was of type: missing.'



 Comments   
Comment by Githook User [ 04/Jul/23 ]

Author:

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

Message: CSHARP-4700: Fix issue with GroupBy followed by OrderBy.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/51cf2ffc02d60fdd54ab3fe89253559ff2e67593

Comment by Robert Stam [ 03/Jul/23 ]

Thank you for reporting this. I have a fix in code review that fixes the issue when using the LINQ3 provider.

Note that when using LINQ2 the provider does not thrown an exception, but the result is incorrect. the resulting IGrouping values are missing the elements.

Comment by PM Bot [ 30/Jun/23 ]

Hi janis.zinn@baramundi.com, 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:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.