aravindnc / mongoose-aggregate-paginate-v2

A cursor based custom aggregate pagination library for Mongoose with customizable labels.
MIT License
131 stars 23 forks source link

Count and Sort extremely slow #56

Open aarongainz opened 6 months ago

aarongainz commented 6 months ago

We're having an issue where the Count and Sort operations drag the aggregate hundreds of times longer than just returning the documents.

We can get the documents for a page back in 200ms or less using a rigged countQuery, but once we drop our .limit() on the countQuery our execution times jump to 60seconds, then if we add a sort, on an indexed field (both in our Search Index and indexed separately) it can take 120+seconds.

Every field we're querying on is indexed. Obiously it's scanning the entire collection in these cases but I can't crack this

trycoon commented 1 month ago

@aarongainz Try the latest version, maybe this fixes your performance issues? https://github.com/aravindnc/mongoose-aggregate-paginate-v2/pull/61