$unwind
dekonstruer runder-arrayet$project
for at vise obligatoriske felter
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"
}
}
])
En mere dynamisk tilgang,
$mergeObjects
at flette obligatoriske felter fra root oground_values
objekt$replaceRoot
for at erstatte ovenstående flettede objekt til root
db.collection.aggregate([
{ $unwind: "$rounds" },
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
GameID: "$GameID",
ComputerName: "$ComputerName"
},
"$rounds.round_values"
]
}
}
}
])