查询MongoDB的时候想直接把总和带出来而不是在代码中去计算
我这边由于才开始使用MongoDB不了解如果在查询计算中处理数组
这里需要把 service节点中的 每个对象中的price节点中的value值相加得到这个订单的总金额,求大佬们给小弟指导一下
数据示例:
{
"project": {
"name":xxx,
"id":112233
},
"comment": null,
"evaluation": 5,
"created": 1559380560020,
"serviceDate": 1559380655784,
"finishDate": 1559384199416,
"serialNumber": 20190429322250,
"service": [
{
"_id": "5ab9c44fc163db1a123c68da",
"name": "代办代买",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "SINGLE",
"unitPrice": 3,
"value": 3,
"count": 1
}
},
{
"_id": "5b20d380d9fe6121d3517587",
"name": "打扫房屋卫生",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "MULTI",
"unitPrice": 1,
"value": 42,
"count": 42
}
},
{
"_id": "5ab9c44f7b571d1a2e766513",
"name": "上门理发",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "SINGLE",
"unitPrice": 10,
"value": 10,
"count": 1
}
},
{
"_id": "5ab9c45068665e1a11c31a03",
"name": "剪指甲",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "SINGLE",
"unitPrice": 3,
"value": 3,
"count": 1
}
},
{
"_id": "5acdb3492f78963f6d2126ad",
"name": "血压.血糖测量,心率.基本生命体征检查等.并建立健康档案",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "SINGLE",
"unitPrice": 25,
"value": 25,
"count": 1
}
},
{
"_id": "5ab9c450c163db1a123c68dc",
"name": "按摩",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "SINGLE",
"unitPrice": 20,
"value": 20,
"count": 1
}
},
{
"_id": "5acc41c72f78963f6d2125fc",
"name": "中药泡脚",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "SINGLE",
"unitPrice": 30,
"value": 30,
"count": 1
}
},
{
"_id": "5ab9c450515a711a286b20d3",
"name": "精神慰藉",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "SINGLE",
"unitPrice": 5,
"value": 5,
"count": 1
}
},
{
"_id": "5acdb349809a383f52a3c1cc",
"name": "灭蚊、灭蟑螂、杀虫",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "SINGLE",
"unitPrice": 10,
"value": 10,
"count": 1
}
},
{
"_id": "5acdb34959bda23f73129961",
"name": "健康和法律知识讲座",
"price": {
"unit": "元",
"categoryUnit": "次",
"category": "SINGLE",
"unitPrice": 5,
"value": 5,
"count": 1
}
}
]
}
相似问题