如何在Node.js中对Mongoose进行分页? [英] How to paginate with Mongoose in Node.js?
本文介绍了如何在Node.js中对Mongoose进行分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用Node.js和猫鼬编写一个Web应用程序.如何对从.find()
调用中获得的结果进行分页?我想要一个与SQL中的"LIMIT 50,100"
相当的功能.
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.
推荐答案
使用Rodolphe提供的信息仔细研究了Mongoose API之后,我想出了以下解决方案:
After taking a closer look at the Mongoose API with the information provided by Rodolphe, I figured out this solution:
MyModel.find(query, fields, { skip: 10, limit: 5 }, function(err, results) { ... });
这篇关于如何在Node.js中对Mongoose进行分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文