【发布时间】:2021-06-08 14:05:17
【问题描述】:
我知道下面的 mongodb 文档可能不是一个理想的结构,但是有什么方法可以解开 $rounds.round_values 吗?
我尝试过使用aggregate([{"$unwind": "$rounds"}]) 或"$rounds.round_values",但这似乎不起作用。非常感谢任何建议。
{
"_id" : ObjectId("60bea750c26a1c7095387d00"),
"rounds" : [
{
"round_number" : "0",
"round_values" : {
"max_player_pot" : "0.25",
"pot_multiple" : "0.625",
},
{
"round_number" : "1",
"round_values" : {
"max_player_pot" : "0.0",
"pot_multiple" : "0.0",
}
],
"GameID" : "392124717",
"ComputerName" : "awdfadf",
}
预期输出:
{
"max_player_pot" : "0.25",
"pot_multiple" : "0.625",
"GameID" : "392124717",
"ComputerName" : "awdfadf",
},
{
"max_player_pot" : "0.0",
"pot_multiple" : "0.0",
"GameID" : "392124717",
"ComputerName" : "awdfadf",
}
【问题讨论】:
-
究竟是什么问题?它运行良好,请参阅playground。
-
我明白了。是的,它可以展开它,但是我怎样才能将整个结构展平以直接在顶层拥有 round_values?
-
能否请您显示您的预期结果以获得更清晰的图片?
-
已编辑问题以澄清
标签: mongodb aggregation-framework pymongo