1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| db.getCollection("b_customer_info_device").aggregate([ { "$unwind": "$devices_statuses" } , { "$lookup": { "from": "b_terminfo", "localField": "devices_statuses.term_id", "foreignField": "term_id", "as": "term_info" } } , { "$unwind": "$term_info" } , { "$match": {} } , { "$project": { "_id": 1, "customer_id": 1, "class_name": 1 , "feature_fail": { "$cond": { "if": { "$eq": ["$devices_statuses.err_msg", "5"] }, "then": 1, "else": 0 } } , "total_fail": { "$cond": { "if": { "$eq": ["$devices_statuses.sync_status", "progressFail"] }, "then": 1, "else": 0 } } } } , { "$group": { "_id": { "_id": "$_id", "customer_id": "$customer_id", "class_name": "$class_name" } , "total_fail": { "$sum": "$total_fail" } , "feature_fail": { "$sum": "$feature_fail" } } } , { "$project": { "_id": 1, "customer_id": 1, "img_store_data": 1, "customer_name": 1, "class_name": 1 , "feature_fail": { "$cond": { "if": { "$gt": ["$feature_fail", 0] }, "then": 1, "else": 0 } } , "total_fail": { "$cond": { "if": { "$gt": ["$total_fail", 0] }, "then": 1, "else": 0 } } } }
, { "$group": { "_id": null , "total_customer": { "$sum": 1 } , "total_fail": { "$sum": "$total_fail" } , "feature_fail": { "$sum": "$feature_fail" } } } ]);
|