Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db.requests.aggregate([
- {$match:{
- "hospital":ObjectId("555cfce9d599f0f12c000007"),
- "materials.products.attended.consumed":{$exists:true}
- }
- },
- {$unwind:"$materials"},
- {$unwind:"$materials.products"},
- {$unwind:"$materials.products.attended"},
- {$group:
- {
- "_id":{"antel_code":"$materials.products.antel_code", "name":"$materials.products.name"},
- "quantity_to_restore":{$sum:{$cond:[{$eq:["$materials.products.assign","LOCAL"]}, "$materials.products.attended.consumed", 0]}},
- "data":{$push:{
- "folio":"$folio",
- //"consumed":"$materials.products.attended.consumed"
- "consumed":{$cond:["$materials.products.attended.consumed", "$materials.products.attended.consumed", null]}
- }
- }
- }
- },
- {$match:{"quantity_to_restore":{$gt:0}}},
- //{$match:{"data.consumed":{$ne:null}}},
- {$sort:{"_id.antel_code":1}}
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement