0

I have a database which store historical data of sensors. Each time I could type a command 'get 1' to get 1,000 data from server. If user type a command 'get 2', he can retrieve another 1,000 data and the whole database is sorted by time. How to retrieve data with query? Also, I concern the performance of database.

This is one of the record format. I have more than 1 billions data in server.

enter image description here

The blank
  • 84
  • 6
  • use cursor https://docs.mongodb.com/manual/reference/method/js-cursor/ – deadshot Oct 16 '21 at 07:30
  • Does this answer your question? [Slow pagination over tons of records in mongodb](https://stackoverflow.com/questions/7228169/slow-pagination-over-tons-of-records-in-mongodb) – ray Oct 16 '21 at 08:42

1 Answers1

1

You can make it by using $skip and $limit.

But a better solution is you get the first 1k documents and then you request another 1k documents with date. Such as below example.

First: 1k docs, date between them are 20210805 ~ 20211016. Second: $sort, { $match: {date: {$lt: 20210805}}}, $limit:1000

YuTing
  • 6,555
  • 2
  • 6
  • 16
  • Thank for you answer. My sampling time doesn't have fixed sampling time interval. I can't use match to do it. $skip may be a good solution in this database – The blank Oct 16 '21 at 08:50