Example of a document inside post collection
{
postId: '232323',
byUser: 'userid1',
post: 'This is my first post',
commentsOnPost: [
{
commentId: '232323_8888',
byUser: 'userid2',
comment: 'Congrats',
repliesOnPost: [
{
replyId: '232323_8888_66666',
byUser: 'userid1',
reply: 'Thanks',
likesOnReplyBy: ['userid1', 'userid5', 'userid3'],
},
{
replyId: '232323_8888_55555',
byUser: 'user2',
reply: 'Welcome',
likesOnReplyBy: ['userid6', 'userid8', 'userid9'],
}
]
}
]
}
I want to query this post such a way so that wherever userid comes I want to replace it from below collection of matched userid.
[
{
userid:userid1,
displayName:'Bob',
profilePic:'https://example.com/bob_profile.png'
},
{
userid:userid2,
displayName:'Lorish',
profilePic:'https://example.com/lorish_profile.png'
}
.
.
.
.
]
Is this possible such query? or Do I need to do referencing at the time of inserting document. I don't want to replace userid one by one by performing many loop.
Expected Output
{
postId:'232323',
byUser: {
userid:userid2,
displayName:'Lorish',
profilePic:'https://example.com/lorish_profile.png'
}
post:'This is my first post',
commentsOnPost:[
{
commentId:'232323_8888',
byUser: {
userid:userid1,
displayName:'Bob',
profilePic:'https://example.com/lorish_profile.png'
},
comment:'Congrats',
repliesOnPost:[
{
replyId:'232323_8888_66666',
byUser: {
userid:userid1,
displayName:'Bob',
profilePic:'https://example.com/lorish_profile.png'
},
reply:'Thanks',
likesOnReplyBy:[
{
userid:userid6,
displayName:'Kiti',
profilePic:'https://example.com/lorish_profile.png'
},
{
userid:userid2,
displayName:'Lorish',
profilePic:'https://example.com/lorish_profile.png'
}
],
},
{
replyId:'232323_8888_55555',
byUser: {
userid:userid2,
displayName:'Lorish',
profilePic:'https://example.com/lorish_profile.png'
},
reply:'Welcome',
likesOnReplyBy:[
{
userid:userid5,
displayName:'Rahul',
profilePic:'https://example.com/lorish_profile.png'
}
],
}
]
}
]
}