Reputation: 705
I would like to find 2nd last record form collection with Meteor. How can I get it. For example if I use SQL I will write query like this:
SELECT TOP 1 * From
(select Top 2 * from student ORDER BY Id DESC)
ORDER BY Id
How about in Meteor.
Thanks in advance.
Upvotes: 3
Views: 1284
Reputation: 8013
Collection.find({}, {sort: {Field: -1}, limit: n}).fetch().pop();
Where:
Collection
is your collection name.Field
is the field you're interested in.n
th last document.Essentially, you're reverse-sorting by the given field, limiting the returned results to only the first n
, and then popping off the last element in that result set (i.e. the n
th).
Upvotes: 5