eherve / mongoose-datatable

Server side dataTable request support for mongoose
MIT License
42 stars 28 forks source link

Move MongoDB project before MongoDB sort #56

Closed adrianjarc closed 5 years ago

adrianjarc commented 5 years ago

I made this pull request because I ran into an issue on a project I am working at. Even though we have indexes set on MongoDB it makes certain querys excruciatingly slow. Bug I mention can be read about on this link: bit.ly/MongoDBSortBug

TL;DR: MongoDB prioritises indexes which enable it non-blocking sort in aggregation pipelines. Therefore it might choose index that is optimal for sort but not the query itself. It can be "fixed" if you put project between match and sort.