1

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.

Community
  • 1
  • 1
Joe
  • 46,419
  • 33
  • 155
  • 245

1 Answers1

2

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.

Derick
  • 35,169
  • 5
  • 76
  • 99
  • Index to help the operation of the grouping or to ensure stability? – Joe Jan 09 '14 at 14:13
  • The index would help the $sort, just to make sure it doesn't need to read all documents to do the $sort. A $sort makes the order stable and also defined. Without the sort you get "natural order", which isn't really specified. – Derick Jan 09 '14 at 15:06