Reputation: 84
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.
Upvotes: 0
Views: 284
Reputation: 6629
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
Upvotes: 1