I have this two COLLECTIONS:
1st.collection
users:
{
_id :34,
name :"mama sita"
}
2nd.collection
posts:
{
_id :67
body :" hello mongoose"
likes:[ 0: ObjectId("34") ]
comments:[
{
_id:9,
body:""mama sita",
likes:[ 0: ObjectId("35") ],
replies:[
{
_id:3,
body:"h"mama sita",
likes:[ 0: ObjectId("35") ],
responses:[
{
_id:3,
body:"hello mama sita",
likes:[ 0: ObjectId("35") ],
}
]
}
]
}
]
}
I wanna get every posts with likes count.
And let suppose if I have a auth user id ready and a want to map through the likes and if the user._id
(auth id) is found in the post likes i wanna append a new attribute to the collection result not in the db , i just want to modifies the result i’m gonna get.
To make more since of my question , this is the result expected :
{
"_id":"45",
"body":"new post mfs",
"likesCount":1,
"commentsCount":1,
"liked":true,
"comments":[
{
"likesCount":1,
"liked":true,
"likes":[
{
"34":"mama mia"
}
],
"_id":"9",
"body":"new post",
"replies":[
{
"likes":[
{
"34":"mama mia"
}
],
"likesCount":1,
"liked":true,
"body":"new post",
"_id":"4",
"responses":[
{
"likes":[
{
"34":"mama mia"
}
],
"likesCount":1,
"liked":true,
"body":"new post",
"_id":"2"
}
}
]
}
]
},