I am writing a webapp with Node.js and mongoose. How can I paginate the results I get from a .find()
call? I would like a functionality comparable to "LIMIT 50,100"
in SQL.
相关问题
- MongoDB can not create unique sparse index (duplic
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Spring Data MongoDB - lazy access to some fields
- google-drive can't get push notifications
- Golang mongodb aggregation
相关文章
- node连接远程oracle报错
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- mongodb error: how do I make sure that your journa
- How can make folder with Firebase Cloud Functions
- How to track MongoDB requests from a console appli
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
After taking a closer look at the Mongoose API with the information provided by Rodolphe, I figured out this solution:
This is example function for getting the result of skills model with pagination and limit options
}
If you are using mongoose as a source for a restful api have a look at 'restify-mongoose' and its queries. It has exactly this functionality built in.
Any query on a collection provides headers that are helpful here
So basically you get a generic server with a relatively linear load time for queries to collections. That is awesome and something to look at if you want to go into a own implementation.
The easiest and more speedy way is, paginate with the objectId Example;
Initial load condition
Take the first and last ObjectId from response data
Page next condition
Page next condition
In mongoose
This is a sample example you can try this,