2 / 2
May 2024

I have a aggregation query used $match at 1st stage and then used $group at 2nd stage with two fields(side and Settlementdate and sum of quantity. So result will be as below:
{
Id: { side: SELL,SettlementDate:2024-05-10},
TotalQty=100000
}
{
Id: { side: BUY,SettlementDate:2024-05-10},
TotalQty=240000
}

Here i want final result as below:

{
Id: { side: SELL,SettlementDate:2024-05-10},
SellTotalQty=100000
}
{
Id: { side: BUY,SettlementDate:2024-05-10},
BuyTotalQty=240000
}
{TotalQty:140000} ----> this is BuyTotalQty-SellTotalQty

Hi @udhaya_kumar_Bagavathiappan, Welcome back,

Please update your post with proper formatting, and also put valid JSON.

Read more about how to format the code,