How to get last 4 elements from meteor collection? For example. Posts = new Meteor.Collection('posts');
I like to get last 4 posts from "Posts" collections.
How to get last 4 elements from meteor collection? For example. Posts = new Meteor.Collection('posts');
I like to get last 4 posts from "Posts" collections.
I assume that you have the date on the Posts items. You can do the following to get the "last post" or top 4 most recent:
Posts.find({}, {sort: {createdAt: -1}, limit: 4});
or if you mean the last or oldest Posts
Posts.find({}, {sort: {createdAt: 1}, limit: 4});