简体   繁体   English

MongoDB获得越来越多的记录

[英]MongoDB get more and more records

How can I get let's say the oldest 5 records from MongoDB using mongoose and after let's say the next 5 records and so on. 我怎么能让我们说使用mongoose的 MongoDB中最老的5条记录,然后让我们说下5条记录,等等。 What I have by now is this 我现在拥有的是这个

Model.find().sort({time: -1}).limit(5).exec( ...);

But I want after some time to get next 5, how can I do this? 但是我希望在一段时间之后能够获得下一个5,我该怎么办呢?

Based on request number update page. 基于请求号更新页面。 eg. 例如。 first request send page=0, for next page=1 and so on. 第一个请求发送页面= 0,下一页= 1,依此类推。

var limit = 5;
var page = 0; // 1,2,3,4

return Model.find()
        .sort({time: -1})
        .limit(limit)
        .skip(limit * page)
        .exec();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM