【问题标题】:Set skip and limit in mongoose sub-document在 mongoose 子文档中设置跳过和限制
【发布时间】:2018-01-03 20:59:27
【问题描述】:
var comment = new Schema({
text: {type:String}
});

var Post = new Schema({
comments : [comment]
});

我有一个帖子对象的“n”条记录,我想根据限制和跳过检索评论数据。

我想在从 Post 模型填充评论数据时为评论模式添加分页。

实现它的方法是什么?

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    您可以使用$slice

    db.posts.find( {}, { comments: { $slice: [ 20, 10 ] } } )
    

    【讨论】:

      猜你喜欢
      • 2017-05-03
      • 2020-06-16
      • 2019-05-31
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 2015-12-20
      • 2019-07-13
      • 2015-03-12
      相关资源
      最近更新 更多