Kurounin / Pagination

This package allows you to paginate the subscriptions over meteor's collections. It can be used in a Blaze template or in ReactJS.
MIT License
56 stars 22 forks source link

Sorting with meteor-collection-helpers #58

Closed egemon closed 6 years ago

egemon commented 6 years ago

I have an array of vote objects as a field of post. I am using meteor-collection-helpers to get number of upvotes and downvotes from this array. I need to sort by this number. Neither {score: 1} or {score(): 1} is not working. Is this issues with subscription or with pagination or am i doing smth wrong?
https://github.com/dburles/meteor-collection-helpers @Kurounin

Kurounin commented 6 years ago

Sorting relies on mongo sort which orders the results by a specific field (not by an aggregation). If your score property is an array, sorting by it won't work. If the score property is an object containing 2 properties (upvotes & downvotes), you can sort by score.upvotes. If you want to sort by overall score, you should keep that number in a property (which should be updated with each upvote/downvote) and sort by it.