我对数据库进行查询。我响应数组。在答案中,我需要获取页面,选择页面,总计。将数据传输到客户端以进行分页
return db.Reviews.findOne({_id: mongoose.Types.ObjectId(options.news_id)}, {comments:1})
.then(res => {
return {
comments: res.comments.map(el => {
return {
_id: el._id,
name: el.name,
author: el.author,
message: el.message,
createdAt: el.createdAt
};
}),
count: {
total: res.comments,
pages: Math.ceil(res.comments /
Number(param.limit)),
select_page: param.page,
limit: param.limit,
offset: param.offset,
}