首页 > 解决方案 > 我正在使用 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”

标签: mongodbaggregation-framework

解决方案


推荐阅读