How to get row sum and column sum using mongoDB aggregation

Viewed 66

I need to filter some data count as per group by and calculate also the row sum and column sum using Mongodb. I am giving one screen shot and as per the screen shot the array of record should fetch using MongoDB query.

output sheet

Here I need the branch wise column total sum and category wise the row total sum. I am explaining my sample documet below.

{

    "OrderNumber" : "EQORD/20/10001694",
    "OrderStatus" : "Delivered",
    "OrderType" : "Online",
    "StoreCode" : "DKWF",
    "StoreName" : "Deeksha, Whitefieldgolbal, Bengaluru",
    "StoreBranch" : "White field",
    "StoreGroupCode" : "DKAA",
    "StoreGroupName" : "Deeksha Group",
    "CategoryInfo" : {
        "category" : {
            "CategoryName" : "Books",
            "ParentPath" : "Books",
            "CategoryCode" : 4000000,
            "CategoryGroup" : "TRUE",
            "level" : "",
            "category" : "category"
        },
    }
}

Here Branch Name from image is StoreName and Uniforms is value of CategoryName from document. So here I need one MongoDB aggregation query to count the total record as per ``StoreNameandCategoryName` along with the grand total value for each row and each column.

0 Answers
Related