如何在 MongoDB 中将 2 个文档放在一起?

问题描述 投票:0回答:1

enter image description here 我的问题如图所示 文档1: [{"_id":"65c093d9717f93bc5fb4d8b8","title":"如何连接vite","description":"新帖子1"} 文档2: {"_id":"65c09794717f93bc5fb4d8bd","title":"hihi","description":"发布新2222"}]

reactjs mongodb mongoose next.js nosql
1个回答
0
投票

从你的问题很难准确说出你的期望。

但据我了解,你想将它们分组并将两个文档彼此排列在一起。

为此,您可以使用

aggregation
$group

[{
    $group: {
        _id: null,
        documents: {
            $push: {
                _id: '$_id',
                title: '$title',
                description: '$description'
            }
        }
    }
}]
© www.soinside.com 2019 - 2024. All rights reserved.