i want to show user list of object with projection and also want to show the total page i want output like this
{
"Success": true,
"message": " Fetched post comment successfully.",
"data": {
"docs": [
{
"_id": "60101fcc4077e698facd63aa",
"commentDetail": {
"hasReply": false,
"likeCount": 0,
"angryCount": 0,
"favCount": 0,
"totalReaction": 0,
"description": "four comment",
"media": null,
"date": "2021-01-26T13:57:32.220Z",
"action": [],
"commentReplies": []
},
"userID": "5f5238b5458b7c63a477bf87",
"postID": "5fb7a19bcae255415e99781b",
"commentID": "60101fcb4077e698facd63a9",
},
{
"_id": "60101fcc4077e698facd63aa",
"commentDetail": {
"hasReply": false,
"likeCount": 0,
"angryCount": 0,
"favCount": 0,
"totalReaction": 0,
"description": "four comment",
"media": null,
"date": "2021-01-26T13:57:32.220Z",
"action": [],
"commentReplies": []
},
"userID": "5f5238b5458b7c63a477bf87",
"postID": "5fb7a19bcae255415e99781b",
"commentID": "60101fcb4077e698facd63a9",
}
],
"count": 1
}
}
i write this query
getPostAllComment = await this.comment.aggregate([
{ $match: { postID: ObjectId(getPostCommentDTO.postID) } },
{ $sort: { createdAt: 1 } }, //sort on created At
{ $skip: (parseInt(getPostCommentDTO.pageNum) - 1) * parseInt(getPostCommentDTO.pageSize) },
{ $limit: parseInt(getPostCommentDTO.pageSize) },
{
$group: {
_id: "$postID",
docs: { $push: "$$ROOT" },
count: { $sum: 1 },
},
},
{ $project: { _id: 0 }
}
it give me output like above which i am expecting but my $project is not working here.so how can i show output exactly like above with total page count field at root level not in each document with projection.i already tried to used $facet but it not give me output like i above explain
question from:
https://stackoverflow.com/questions/65898519/pagination-in-aggregation-and-also-used-project-in-mongoose