-
$unwindラウンド配列を分解します -
$project必須フィールドを表示するには
db.collection.aggregate([
{ $unwind: "$rounds" },
{
$project: {
GameID: 1,
ComputerName: 1,
max_player_pot: "$rounds.round_values.max_player_pot",
pot_multiple: "$rounds.round_values.pot_multiple"
}
}
])
より動的なアプローチ
-
$mergeObjectsルートとround_valuesから必須フィールドをマージします オブジェクト -
$replaceRoot上記のマージされたオブジェクトをルートに置き換える
db.collection.aggregate([
{ $unwind: "$rounds" },
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
GameID: "$GameID",
ComputerName: "$ComputerName"
},
"$rounds.round_values"
]
}
}
}
])