0

I have a MongoDB collection that collects usage stats from the network in Octets. I have the following query that gives me at least a non 0 sum in MongoDB Compass but it give me 0 when I run it on MongoShell.

db.audit_auth_2022_05.aggregate([
    {$project: {
      params: 1,
      updateTime: 1,
      totalSum: {$add:["$params.Acct-Input-Octets","$params.Acct-Output-Octets"]}
     }},
     {$group: {
       _id: {
         day: {$substr:["$updateTime",0,10]}
       },
       UsageOctets: {$sum: "$totalSum"}
     }}
])
    
    **Result:**
        { "_id" : { "day" : "2022-05-16" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-06" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-01" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-08" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-02" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-12" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-15" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-03" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-05" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-04" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-07" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-13" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-09" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-14" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-11" }, "UsageOctets" : 0 }
        { "_id" : { "day" : "2022-05-10" }, "UsageOctets" : 0 }

sorry for being a bit crude on this, sample data 1 entry below;

{
        "_id" : ObjectId("626db1610c9d5d9d765d3982"),
        "action" : "OK",
        "description" : "LLID does not have active bundle quota",
        "params" : {
                "Alc-SAP-Session-Index" : 1,
                "NAS-IP-Address" : ""99.99.99.99"",
                "NAS-Port-Id" : "3/2/1:107.1915",
                "transactionId" : "authentication;"99.99.99.99"",
                "User-Name" : "B510016911",
                "Acct-Session-Id" : "BF81762A2687F262619F0B"
        },
        "result" : {
                "Alc-Subsc-Prof-Str" : "GPON_20480_V2",
                "Framed-Pool" : "saix002ipc1",
                "Alc-Ipv6-Primary-Dns" : "fdf8:f53b:82e4::53",
                "Alc-Subscriber-QoS-Override" : [
                        "i:p:2:pir=22528,mbs=204800",
                        "e:q:2:pir=22528,mbs=204800"
                ],
                "Alc-Portal-Url" : "mycompany.com/openserveisp/failureDataBundleNotFound.htm?sub=$SUB",
                "Alc-Retail-Serv-Id" : "1050031",
                "Alc-Subsc-ID-Str" : "B510016911",
                "Alc-Primary-Dns" : "99.99.99.99",
                "Alc-Secondary-Dns" : "99.99.99.99",
                "Acct-Interim-Interval" : "300",
                "Alc-Ipv6-Secondary-Dns" : "fdf8:f53b:82e4::53",
                "Alc-SLA-Prof-Str" : "QP_GD2_1",
                "Alc-Subscriber-Filter" : "Ingr-v4:20004,Egr-v4:20005",
                "Reply-Message" : "LLID does not have active bundle quota",
                "action" : "OK",
                "Session-Timeout" : "0"
        },
        "api" : "authentication",
  `enter code here`      "updateTime" : "2022-05-01 00:00:01",
        "updateTimeEpoch" : NumberLong("1651356001548")
}

I think my problem might stem from adding 2 individual array objects using $add. I performed the following and and got a null result;

 db.audit_auth_2022_05.aggregate([{$project: {updateTime: 1,totalSum: {$add:['$params.Acct-Input-Octets','$params.Acct-Output-Octets']}}}])
{ "_id" : ObjectId("626db160aa7b1dc68a5aacd6"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db1600c9d5d9d765d3979"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db160aa7b1dc68a5aacd7"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db1600c9d5d9d765d397a"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db1600a2e673ead04e2fa"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db160aa7b1dc68a5aacd8"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db1600c9d5d9d765d397b"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db1600a2e673ead04e2fb"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db1600a2e673ead04e2fc"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db160aa7b1dc68a5aacd9"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db1600c9d5d9d765d397d"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db1600c9d5d9d765d397f"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db1600a2e673ead04e2fd"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db161aa7b1dc68a5aacda"), "updateTime" : "2022-05-01 00:00:00", "totalSum" : null }
{ "_id" : ObjectId("626db161aa7b1dc68a5aacdb"), "updateTime" : "2022-05-01 00:00:01", "totalSum" : null }
{ "_id" : ObjectId("626db1610a2e673ead04e2ff"), "updateTime" : "2022-05-01 00:00:01", "totalSum" : null }
{ "_id" : ObjectId("626db1610c9d5d9d765d3980"), "updateTime" : "2022-05-01 00:00:01", "totalSum" : null }
{ "_id" : ObjectId("626db1610c9d5d9d765d3981"), "updateTime" : "2022-05-01 00:00:01", "totalSum" : null }
{ "_id" : ObjectId("626db1610c9d5d9d765d3982"), "updateTime" : "2022-05-01 00:00:01", "totalSum" : null }
{ "_id" : ObjectId("626db161aa7b1dc68a5aacdf"), "updateTime" : "2022-05-01 00:00:01", "totalSum" : null }

0 Answers0