Single fetch with skip and limit returns unexpected result

Hi @Energy_N_A, @steevej,

The issue is that is sorting by identical values does not produce a deterministic sort order:

Per Using skip() with sort() in the documentation:

If using skip() with sort() , be sure to include at least one field in your sort that contains unique values, before passing results to skip() .

Sorting on fields that contain duplicate values may return an inconsistent sort order for those duplicate fields over multiple executions, especially when the collection is actively receiving writes.

The easiest way to guarantee sort consistency is to include the _id field in your sort query.

Regards,
Stennie

3 Likes