Limits: Unresolved Ordering of .skip() and .limit() in Mongoose Queries
0 reputation · 02 Oct 2026, 00:37 UTC
Limits: Unresolved Ordering of .skip() and .limit() in Mongoose Queries
In Mongoose 7.x, the .limit() and .skip() modifiers are documented as caps on result sets. However, the framework does not prescribe a fixed order relative to .sort() or .lean(). Under high concurrent traffic, the query planner may choose different execution paths depending on modifier order, potentially affecting latency and the exact slice of documents returned.
Because the MongoDB driver’s default connection pool size is 5, concurrent requests can experience contention, and the placement of .skip() and .limit() may influence how many operations are queued. The community has not finalized whether applying .skip() before .sort() should be recommended for consistent pagination.
What is the impact on latency when .skip() precedes .sort() versus when it follows? Does the order affect the correctness of the returned page under concurrent load? Should Mongoose expose a configuration to enforce a particular modifier sequence for pagination queries?