mongoose-paginate-v2
mongoose-paginate-v2 copied to clipboard
Sort doesn't work with mongoose-paginate (but works with vanilla mongoose)
I have a collection of calendar Events
and in their schema is a start
key which holds a proper date. If I run a vanilla mongoose query such as...
Event.find(filter).sort( { start: 1 } ).limit(250)
...as expected, I get a list of events, sorted oldest to newest.
However, when I run...
const options = {
sort: 'start'
// or sort: { start: 1 }
}
Event.paginate(filter, options)
...I successfully have paginated results returned; however, they're not in any specific order.
I've attempted to make start
an index at both the field and schema level but to no avail. Am I missing a step or syntax?
I just came from mongoose-aggregate-paginate-v2 here because it seems it's bugged when it comes to sorting, and now I'm reading this. Please if someone can confirm if this is a confirmed bug?
Actually I realised I don't need aggregation in my query and this paginate-v2 would suit me really well because it has same output fields as aggregate version, so I don't have to change my frontend. But I do need sorting of paginated results pretty badly...
@JoshuaPerk Seems sorting issue is happening for random users. I've tested with different scenarios and didn't get any issues till now.
I'm also getting this issue, is there any workaround or fix coming? I'm using Mongoose v6.1.4. Thanks
Same issue. any luck so far?
What I tried here that worked for me was including _id
in the sort fields