aravindnc / mongoose-paginate-v2

A custom pagination library for Mongoose with customizable labels.

Home Page:https://www.npmjs.com/package/mongoose-paginate-v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to sort paginated results by fulltext's textScore meta data?

trancephorm opened this issue · comments

commented

Please anyone tell me if he actually did it, I don't want to lose days just to realize you can't do it. Thanks! :)

commented

Seems like I managed to get paginated results sorted by textScore by default, now I just need to confirm it, anyone help me how to include textScore metadata in resultset?

You can add text score in projection for this,

projection: { score: { $meta: "textScore" } }
commented

Thanks a lot, I've put it in options and it works... I'm now just curious how it doesn't replace the current result set with just that one score: property, because this is where it says that projection is overwriting current collection of properties: https://mongoosejs.com/docs/api/query.html#query_Query-projection

Glad to hear that solved your problem. Regarding your other question, that's outside the scope of this plugin. May you will find an answer in the mongoose/mongodb community.