node.js - 如何在 Mongoose 查询中设置限制、偏移、跳过

标签 node.js express mongoose

我正在使用express,mongoose,node.so我已经检查了有关跳过和限制文档的查询。

   Model.find({},null,{limit:2,skip:20},function(err,data){
           //console.log(data)
      })

最佳答案

不确定,但我认为这对您很有帮助。

var perPage = 10
  , page = Math.max(0, req.param('page'))

Event.find()
    .select('name')
    .skip(perPage * page)
    .limit(perPage)
    .sort({
        name: 'asc'
    })
    .exec(function(err, events) {
        Event.count().exec(function(err, count) {
            res.render('events', {
                events: events,
                page: page,
                pages: count / perPage
            })
        })
    })

或查看

How to paginate with Mongoose in Node.js?

关于node.js - 如何在 Mongoose 查询中设置限制、偏移、跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39719021/

相关文章:

node.js - 还有其他方法可以处理Express Node 中的异常吗?

node.js - 使用 Mongoose 更新 MongoDB 文档,而不删除文档中已有的信息

node.js - Jasmine 测试用例不会从 mongo 保存返回

mysql - 一些 curl 命令的发布请求失败,但其他的则没有

Node.js/Express.js session management cookie 为 session cookie

javascript - NodeJs + ExpressJS : router level middleware not able to take the request

mongodb - 发布数据时出现超时错误

node.js - Strongloop(环回)类方法

javascript - bluebird promisify 函数未转换为 Promise

javascript - 使用 Stormpath 进行 Node.Js 身份验证