对于以下JSON,我想执行以下操作:
添加字段total
的值,即(16 + 0 + 60 + 80)
执行上述操作,但按type
进行过滤:
JSON :
{
"_id" : ObjectId("5bbdf40b59c9421e2ae588f5"),
"projectType" : "Residential",
"url" : "http://up-rera.in/Frm_View_Project_Details.aspx?id=10440",
"projectId" : "UPRERAPRJ10440",
"numberOfApartment" : NumberInt(156),
"apartmentType" : "Apartment/Flat/Shop",
"location2" : "Agra",
"location3" : "Agra",
"dateOfCompletion" : "24-03-2020",
"units" : [
{
"total" : NumberInt(16),
"type" : "4 BHK"
},
{
"total" : NumberInt(0),
"type" : "OTHER"
},
{
"total" : NumberInt(60),
"type" : "2 BHK"
},
{
"total" : NumberInt(80),
"type" : "3 BHK"
}
],
"state" : "uttar pradesh",
"projectName" : "APARNA PANCHSHEEL",
"projectStatus" : "Ongoing",
"projectStartDate" : "03-07-2013"
}
我正在使用Studio 3T。我正在使用的当前代码是
{
_id: "$location2",
totalUnits: { $sum: "$units.total" }
}
任何帮助将不胜感激。