通过MongoDB中的骨料结构数据
我一直在通过MongoDB中的汇总FREMWORK创建收集的统计信息,我想创建一个包含用户ID的对象,而Arry包含用户拥有的呼叫指示(出站,入站等)方向和在Spesific方向上拨打的总呼叫。
例如:
我有此文档:
{
"userId" : "628pp9d91ce06ba3ed6cb0pf6",
"date" : "1655983001341",
"direction" : "outbound",
"duration" : 35.0,
"network" : null,
"status" : "completed",
"from" : "src-1",
"company" : "companyName",
}
我试图通过类似的同意制作统计文档:
db.test.aggregate([
{$match : { company : "companyName"}},
{$group : { _id : "$userId", data : { $addToSet : { direction : "$direction", duration : { $sum : "$duration"}, amount : { $sum : 1} } } } }
])
预期值必须为:
{
"_id" : "---",
"data" : [
{
"direction" : "unanswered",
"duration" : 26.0,
"amount" : 3.0
},
{
"direction" : "outbound",
"duration" : 863.0,
"amount" : 3.0
}
]
}
但是我得到的输出是:
{
"_id" : "6268f634106db6972be89241",
"data" : [
{
"direction" : "unanswered",
"duration" : 12.0,
"amount" : 1.0
},
{
"direction" : "outbound",
"duration" : 767.0,
"amount" : 1.0
},
{
"direction" : "outbound",
"duration" : 41.0,
"amount" : 1.0
},
{
"direction" : "outbound",
"duration" : 55.0,
"amount" : 1.0
},
{
"direction" : "unanswered",
"duration" : 1.0,
"amount" : 1.0
},
{
"direction" : "unanswered",
"duration" : 13.0,
"amount" : 1.0
}
]
}
我做错了什么?
i have been tring to create statistics for a collections via the aggregate fremwork in mongodb, i want create an object that contains user id, and arry that contains the calls directions the user had (outbound, inbound etc.) the total air duration of each direction and the total amount of calls that made at the spesific direction.
for example :
I have this document :
{
"userId" : "628pp9d91ce06ba3ed6cb0pf6",
"date" : "1655983001341",
"direction" : "outbound",
"duration" : 35.0,
"network" : null,
"status" : "completed",
"from" : "src-1",
"company" : "companyName",
}
and i tried to make a statistics docs via agreggate like that :
db.test.aggregate([
{$match : { company : "companyName"}},
{$group : { _id : "$userId", data : { $addToSet : { direction : "$direction", duration : { $sum : "$duration"}, amount : { $sum : 1} } } } }
])
the expected value need to be :
{
"_id" : "---",
"data" : [
{
"direction" : "unanswered",
"duration" : 26.0,
"amount" : 3.0
},
{
"direction" : "outbound",
"duration" : 863.0,
"amount" : 3.0
}
]
}
but the output i gets is :
{
"_id" : "6268f634106db6972be89241",
"data" : [
{
"direction" : "unanswered",
"duration" : 12.0,
"amount" : 1.0
},
{
"direction" : "outbound",
"duration" : 767.0,
"amount" : 1.0
},
{
"direction" : "outbound",
"duration" : 41.0,
"amount" : 1.0
},
{
"direction" : "outbound",
"duration" : 55.0,
"amount" : 1.0
},
{
"direction" : "unanswered",
"duration" : 1.0,
"amount" : 1.0
},
{
"direction" : "unanswered",
"duration" : 13.0,
"amount" : 1.0
}
]
}
what do i do wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论