mongodb - 我正在使用 mongodb 聚合,它期望不同的输出,但没有得到所需的输出
问题描述
实际上想要输出,RSPI:348
但得到如下。任何人都可以帮助我。
have used below query.am using mongo db aggregations where i want to group by scac(whose value is dqFact) and count how many orders got delayed for particular scac so i did as below.can any one please correct me
aggregate([
{
'$match' : {
'salesOrder.shipDate' : {
'$gte' : '2021-03-18T00:00:00',
'$lte' : '2021-03-18T23:59:59'
}
}
},
{ "$match": { "dqCategory" : "shipmentdata" } },
{ "$match": { "dqState" : "fail" } },
{ "$match": { "salesOrder.region" : "US" } },
{
"$group" : {
"_id": {
"scac": "$dqFact",
"shipDelay": "$dqMeasure.shippeddelay"
}
}
},
{
"$project": {
"_id": 0,
"dqMeasure.shippeddelay": 1,
"dqFact":1
}
}
])
上面的查询是
{
"_id" : {
"scac" : "RPSI",
"shipDelay" : "31"
}
}
/* 2 */
{
"_id" : {
"scac" : "RPSI",
"shipDelay" : "317"
}
}
实际上我使用的查询没有给出我想要的结果。我需要特定 scac 的发货延迟计数。这里的 scac 之一是 RSPI,如下所示。{“_id”:{RSPI:348}}
文档结构是
“event”:{“eventId”:“xxxxxxxxxxxxxxxxxx”,“eventTimestamp”:“2021-05-27 10:12:50”},“salesOrder”:{“orderNum”:“1111111111”,“buid”:“xx ","orderStatus":"xx","statusCode":"xx","orderDate":"2021-05-27 10:01:42.000","shipDate":"2021-03-23T02:54:18" ,“区域”:“xx”,“cotStatus”:“XX”,“companyNum”:“XX”,“LOB”:“PowerEdge”,“orderType”:“XX”,“orderTypeCategory”:“XX”,“ shipToCountryCode”:“XX”,“itemNum”:“XX”,“itemDesc”:“XX”,“orderSource”:“XX”、“classificationCode”:“SYSTEM”、“poNumber”:“XXXX”、“shippingCode”:“8”
解决方案
推荐阅读
- mysql - 如何在mysql中获取所有保存点状态列表
- node.js - Azure Function App 从存储帐户动态获取 Blob 内容并通过邮件将内容作为附件发送
- php - 使用 Google Calendar API PHP 获取事件颜色
- python - 对熊猫数据框中的列进行分组并减少数量
- wso2 - 将 api 从版本 3.1.0 迁移到 3.2.0 后出现 api 调用问题
- asp.net-mvc - 使用 Viewdata 在 Html.Label 中显示 IP 地址
- networking - 查看 wlan0 设备是否忙
- grafana - Influxdb GroupBy 时间使用预定义的时间间隔,并且不以第一个时间戳开始
- laravel - snappy pdf 生成中 %pdf 之前的空格
- xml - Oracle XML - 向标签名称添加额外的文本