Advertisement
Guest User

Untitled

a guest
May 24th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. db.requests.aggregate([
  2. {$match:{
  3. "hospital":ObjectId("555cfce9d599f0f12c000007"),
  4. "materials.products.attended.consumed":{$exists:true}
  5. }
  6. },
  7. {$unwind:"$materials"},
  8. {$unwind:"$materials.products"},
  9. {$unwind:"$materials.products.attended"},
  10. {$group:
  11. {
  12. "_id":{"antel_code":"$materials.products.antel_code", "name":"$materials.products.name"},
  13. "quantity_to_restore":{$sum:{$cond:[{$eq:["$materials.products.assign","LOCAL"]}, "$materials.products.attended.consumed", 0]}},
  14. "data":{$push:{
  15. "folio":"$folio",
  16. //"consumed":"$materials.products.attended.consumed"
  17. "consumed":{$cond:["$materials.products.attended.consumed", "$materials.products.attended.consumed", null]}
  18. }
  19. }
  20. }
  21. },
  22. {$match:{"quantity_to_restore":{$gt:0}}},
  23. //{$match:{"data.consumed":{$ne:null}}},
  24. {$sort:{"_id.antel_code":1}}
  25. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement