简体   繁体   中英

Mongodb pagination with nice URL

Old story pagination with nodejs and mongodb. I use this query to get data.

db.myCollection.find({_id : { $gt : last_id}}).limit(10); 

The url I want look like this

example.com?page=1
example.com?page=2
.....

So how to pre-calculate the last_id of each page without have it in url?

example.com?last_id=5a1b7dd722ecdf29879f4a59

Thanks you

无需查询最后一个ID即可获取下一页,您只需使用skip即可跳过之前的记录并获取接下来的10条记录

db.collection.find().skip(pageNumber > 0 ? ((pageNumber-1)*nPerPage) : 0).limit(nPerPage)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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