Joe
Joe

Reputation: 47609

Is the aggregation output order stable for the purposes of pagination?

The answer to this question suggested doing the following

db.user_tracking.aggregate( {$limit: X}, {$skip: Y}, {$group: {_id: "$q"} ) 

Is the output ordering guaranteed to be stable and consistent? If I page through results can I guarantee that I will recieve every value exactly once?

Assuming the collection doesn't change.

Upvotes: 1

Views: 618

Answers (1)

Derick
Derick

Reputation: 36774

Yes, it is stable as long as the collection doesn't change. Changes include updates to documents as well however. But if you can do a sort (as first operand), that would probably a good addition too. Please make sure you have an index on that though.

Upvotes: 2

Related Questions