4

帖子集合中的文档示例

{
    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'],

                    }
                ]
            }
        ]
}

我想以这种方式查询这篇文章,以便无论用户标识来自哪里,我都想从匹配的用户标识集合中替换它。

[
 {
  userid:userid1,
  displayName:'Bob',
  profilePic:'https://example.com/bob_profile.png'
 },

 {
  userid:userid2,
  displayName:'Lorish',
  profilePic:'https://example.com/lorish_profile.png'
 }

.
.
.
.

]

这可能是这样的查询吗?或者我是否需要在插入文档时进行引用。我不想通过执行多次循环来一一替换用户标识。

预期产出

{
    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'
                        }
                    ],
                    
                }
            ]
        }
    ]
}
4

0 回答 0