Finding most recent entry in a meteor collection

前端 未结 2 1423
情歌与酒
情歌与酒 2021-01-13 11:19

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.

2条回答
  •  温柔的废话
    2021-01-13 11:57

    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.

提交回复
热议问题