Mongo find sort limit client side, not in helper

I need to query on a collection to get the 5 most expensive elements on client side I have written the following:

var topDescending=Products.find({Active:1},{sort:{Cost:-1}},{limit:5} ).fetch()

But cannot get what I want.
This significant collection has been published from server side and subscribed from client side with no limit since in other cases on client side I need to access the collection without limit. So I don’t believe that limiting on publish/subscribe is what I need.
The above is written in order to further be set in a Session variable, it is not included in a helper.
I added this line after fetching

var topFive=topDescending.slice(0,5)

But is there any other better way for the limit to work straight forward?

What do you see as the result of your query as it is? The whole list or nothing is returned?

@konsarna I think you have {limit:5} as a third argument where it should be part of the second. I.e. the code should be:

const topDescending = Products.find({ Active:1 }, { sort: {Cost: -1}, limit: 5 }).fetch()
2 Likes

you were absolutely right @gunn
Thank you so much!!