How to get the latest and oldest record in mongoose.js (or just the timespan between them)

前端 未结 5 761
面向向阳花
面向向阳花 2020-12-12 23:59

Basic problem

I have a bunch of records and I need to get latest (most recent) and the oldest (least recent).

When googling I found this topic where I saw

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 00:29

    We have method called sort using that we can able to get first element(old document) which means 1 for sort field or last element(new document) which means -1 for sort field of collection.

提交回复
热议问题