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 could only get the desired result by doing
let commentsTmp: Comment = Comments.findOne({ parentId: this.currentPost._id }, { sort: { time: -1 } });
with MongoObservable.Collection<T>
Hope this will help someone.
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.