【发布时间】:2018-01-03 20:59:27
【问题描述】:
var comment = new Schema({
text: {type:String}
});
var Post = new Schema({
comments : [comment]
});
我有一个帖子对象的“n”条记录,我想根据限制和跳过检索评论数据。
我想在从 Post 模型填充评论数据时为评论模式添加分页。
实现它的方法是什么?
【问题讨论】:
var comment = new Schema({
text: {type:String}
});
var Post = new Schema({
comments : [comment]
});
我有一个帖子对象的“n”条记录,我想根据限制和跳过检索评论数据。
我想在从 Post 模型填充评论数据时为评论模式添加分页。
实现它的方法是什么?
【问题讨论】:
您可以使用$slice。
db.posts.find( {}, { comments: { $slice: [ 20, 10 ] } } )
【讨论】: