Try to search your question here, if you can't find : Ask Any Question Now ?

Why doesn't mongo maintain $sort order after $skip when sort value is the same?

HomeCategory: stackoverflowWhy doesn't mongo maintain $sort order after $skip when sort value is the same?
Avatarpragati asked 1 week ago

My data looks like this:

{ _id: 1, x: "abc", y: "def"}
{ _id: 2, x: "abc", y: "efg"}
{ _id: 3, x: "xxx", y: "xxx"}

My query looks like this:

db.col.aggregate([{ $sort: { x: 1 } },{ $skip: 0 } ])

When I run that query, i see everything in order: 1, 2, 3
When I change skip to 1, i get 1,3
When it does the sort, is it internally recognizing that docs 1 and 2 are sorted on the same value and using a different method to choose which to use if skipping? Is there any way around this?

1 Answers
Best Answer
AvatarJyoti answered 1 week ago
Your Answer

13 + 19 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com