MongoDB使用聚合转换数据
我收集了以下数据MongoDB使用聚合转换数据,mongodb,aggregation-framework,Mongodb,Aggregation Framework,我收集了以下数据 [ {name: "a", status: 1}, {name: "a", status: 2}, {name: "a", status: 3}, {name: "b", status: 1}, {name: "b", status: 4}, {name: "c", status: 1}, {name: "c", status: 1}, {name: "c", status: 5} ] 我希望将其转换为: {
[
{name: "a", status: 1},
{name: "a", status: 2},
{name: "a", status: 3},
{name: "b", status: 1},
{name: "b", status: 4},
{name: "c", status: 1},
{name: "c", status: 1},
{name: "c", status: 5}
]
我希望将其转换为:
{
names: ["a", "b", "c"],
statuses: [1, 2, 3, 4, 5],
count: [
[1, 1, 1, 0, 0],
[1, 0, 0, 1, 0],
[2, 0, 0, 0, 1]
]
}
说明:
db.collection1.aggregate([
{
$group: {
_id: {environment: "$name", status: "$status"},
count:{$sum: 1}
}
}
])
谢谢很好!现在你能展示一下你到目前为止都做了些什么吗。。聚合([{$group:{{u id:{name:$name,status:$status},count:{$sum:1}}}])不要在这里发布代码。在你的问题上使用。我把它添加到问题中了好!现在你能展示一下你到目前为止都做了些什么吗。。聚合([{$group:{{u id:{name:$name,status:$status},count:{$sum:1}}}])不要在这里发布代码。在你的问题上使用。我把它添加到了问题中