Home > database >  Consult mongo aggregation query problem
Consult mongo aggregation query problem

Time:10-13

 
{" warehouseNsId ":" 15 ", "brandId" : 37, "financeOwnerId:" 1231882808817905665, "currencyUnit" : "CNY", "amount" : 0, "items" : [{" goodsNsId ":" 1353 ", "price" : "256.00", "count" : 1}, {" goodsNsId ":" 1799 ", "price" : "254.80", "count" : 1}, {" goodsNsId ":" 1353 ", "price" : "256.00", "count" : 1}]}



How data as above, there are a number of article, according to the items. GoodsNsId grouping? It is concluded that the following data: expectations

 
{" warehouseNsId ":" 15 ", "brandId" : 37, "financeOwnerId:" 1231882808817905665, "currencyUnit" : "CNY", "amount" : 0, "items" : [{" goodsNsId ":" 1353 ", "price" : "512.00", "count" : 2}, {" goodsNsId ":" 1799 ", "price" : "254.80", "count" : 1}]}

CodePudding user response:

 
{
"WarehouseNsId" : "15", "brandId" : 37, "financeOwnerId:" 1231882808817905665, "currencyUnit" : "CNY", "amount" : 0,
"Items" : [
{" goodsNsId ":" 1353 ", "price" : "256.00", "count" : 1},
{" goodsNsId ":" 1799 ", "price" : "254.80", "count" : 1},
{" goodsNsId ":" 1353 ", "price" : "256.00", "count" : 1}
]
}


The following expectation, how to write the related query statement?
 
{
"WarehouseNsId" : "15", "brandId" : 37, "financeOwnerId:" 1231882808817905665, "currencyUnit" : "CNY", "amount" : 0,
"Items" : [
{" goodsNsId ":" 1353 ", "price" : "512.00", "count" : 2},
{" goodsNsId ":" 1799 ", "price" : "254.80", "count" : 1}
]
}


  • Related