You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.3.2
Node.js version
18.20.2
MongoDB server version
6.X
Typescript version (if applicable)
No response
Description
My CourseModel contains fields as title and code and other fields.
I have 3 courses with the same title "Communication" among tens of courses but different code "COM10", "COM11", "COM12".
I want to paginate the complete list by 10 and these 3 courses are between the 9th and 11th position. One is missing and one is in double between the two pages.
I remember I had the same issue with testing data I had to avoid same creation date to keep my unit tests clean. We updated mongoose from 7.5.0 to 8.0.0 in last november.
This may not necessarily be a bug. Its sorting documents with the same title and so order doesn't matter in that case which may cause the behavior being described.
vkarpov15
added
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
and removed
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
labels
Jul 2, 2024
This is expected behavior on the MongoDB server. await CourseModel.find().sort('title') doesn't guarantee order beyond the title prop, so if you have multiple docs with the same title MongoDB may order them in any way in the result set.
There's a couple workarounds:
Sort by title and code: await CourseModel.find().sort({ title: 1, code: 1 }).limit(10).skip(10)
Sort by title and _id: await CourseModel.find().sort({ title: 1, _id: 1 }).limit(10).skip(10)
Prerequisites
Mongoose version
8.3.2
Node.js version
18.20.2
MongoDB server version
6.X
Typescript version (if applicable)
No response
Description
My CourseModel contains fields as title and code and other fields.
I have 3 courses with the same title "Communication" among tens of courses but different code "COM10", "COM11", "COM12".
I want to paginate the complete list by 10 and these 3 courses are between the 9th and 11th position. One is missing and one is in double between the two pages.
I remember I had the same issue with testing data I had to avoid same creation date to keep my unit tests clean. We updated mongoose from
7.5.0
to8.0.0
in last november.Steps to Reproduce
Expected Behavior
The text was updated successfully, but these errors were encountered: