【发布时间】:2021-08-30 00:07:42
【问题描述】:
美好的一天, 我正在使用 MEAN 堆栈创建一个社交媒体应用程序,其中将包含一个选项来列出您关注的用户,但是,根据 Collections.Find() 已被弃用,我使用 Colletions.estimatedDocumentCount() 以 JSON 格式列出用户(目前我正在使用邮递员对其进行测试)。
它显示了用户数量和您关注的用户数量,但是 JSON 中没有更多数据可显示。
这是我的功能。任何帮助将不胜感激
function getFollowTest(req,res){
var userId = req.user.sub;
if (req.params.id) {
user.id = req.params.id;
}
var page = 1;
if (req.params.page) {
page = req.params.page;
}
var itemsPerPage = 4;
Follow.estimatedDocumentCount({user:userId})
.populate({path: 'followed'})
.paginate(page, itemsPerPage, (err, follows, total)=>{
if (err) return res.status(500).send({message:'Server error'});
if (!follows) return res.status(404).send({message:'you are not following any user'});
res.status(200).send({
total: total,
pages: Math.ceil(total/itemsPerPage),
follows
});
});
}
【问题讨论】:
-
你的问题是什么?我看到 API 返回结果。
-
你好,它应该显示总数,多少页和以下(应该显示用户ID,姓名,姓氏电子邮件等)
标签: javascript node.js database mongodb