Finding most recent entry in a meteor collection
meteor
Solution
As per the docs you can also do:
return Collection.findOne({}, {sort: {DateTime: -1, limit: 1}});
Provided that `DateTime` is this field that you do `Date.parse(Date())`. Also you don't have to store dates as unix timestamps you can just do `new Date()` and it would be stored as the `Date` object type.
Problem
My task sounds simple, but I can't nail down how to write this... I simply want to find the most recent item inserted into a collection and display it on my meteor app. I've been playing with Collection.find() with no real results. This is the last line I've tried: (keep in mind these names are placeholder. My collection is not called Collection in my code) ``` Template.tempname.tempitem = function () { return Collection.find({}, {sort: {DateTime: -1, limit: 1,}}); }; ``` I have a feild in the collection that is the result of Date.parse(Date()) which should allow me to sort by most recent. There is likely other ways to do this, but this was the first solution I came up with.