[SERVER-28195] $skip followed by $limit in aggregation resort & lost records when $sort by equal values Created: 05/Mar/17 Updated: 27/Oct/23 Resolved: 13/Mar/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | 3.4.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Alexandr | Assignee: | Kelsey Schubert |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
targetMinOS: Windows 7/Windows Server 2008 R2 |
||
| Attachments: |
|
||||||||||||||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: |
|
||||||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||||||
| Description |
|
Seems, issue exists only when you $sort records having equal value (rating here)
here we:
there is no this record on next 5
|
| Comments |
| Comment by Ramon Fernandez Marina [ 14/Mar/17 ] | ||||||||||||||||||||||||||
|
trueshura, to add to Thomas' answer, here's a small test that I think shows how $sort behaves:
The same behavior exhibits in 3.4, 3.2, 3.0, 2.6 and 2.4 (the integers in the order array are the _id of the documents):
As Thomas points out, an additional sort is needed to get the behavior you're looking for. Regards, | ||||||||||||||||||||||||||
| Comment by Kelsey Schubert [ 10/Mar/17 ] | ||||||||||||||||||||||||||
|
Hi trueshura, There are number of reasons that the ordering of results with the same sort key might not be stable:
To ensure that the sort order is consistent across queries, we recommend including a unique field, such as _id in your sort order. This suggestion is described by Mathias on I've opened Thank you, | ||||||||||||||||||||||||||
| Comment by Kelsey Schubert [ 05/Mar/17 ] | ||||||||||||||||||||||||||
|
Hi trueshura, Thank you for reporting this behavior, we're able to reproduce and are investigating. Please continue to watch this ticket for updates. Kind regards, |