How do i limit to a collection with sorting

’ return PublichChatRoom.find({}, {sort: {createAt: -1}}).limit(10);
doesnt work

return PublichChatRoom.find().limit( 5 ).sort( { createAt: -1 } );
doesnt work

    return PublichChatRoom.find({}, {sort: {createAt: -1}},{limit:1});

doesnt work

but in google search i found this but its not working
// db.bios.find().sort( { name: 1 } ).limit( 5 )’

how do i limit and sort collection

in browser console

MasterCategories.find({},{sort: {priority: 1}, limit: 2}).fetch()
[Object, Object]

To make it short - sort and limit are in same argument, so in same {}

3 Likes

works without fetch

but why the syntax which was given by mongodb documentation didn work

It is possible to issue standard MongoDB commands to a collection (using the rawCollection method) from the server, but for Meteor’s isomorphic MongoDB layer, you should refer to the Meteor documentation first.

1 Like