Guest User

Untitled

a guest
Oct 11th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. $group:
  2. {
  3. _id:'$_id.staffId',
  4. name: {$first: '$_id.firstName'},
  5. statuses:
  6. {
  7. $push:
  8. {
  9. status:'$_id.status',
  10. count:'$count'
  11. }
  12. },
  13. staffCount: {$sum: '$count'}
  14. }
  15.  
  16. {
  17. "_id" : "00238061",
  18. "name" : "Kirstie Rachel Wong",
  19. "statuses" : [
  20. {
  21. "status" : "Pending",
  22. "count" : 1.0
  23. },
  24. {
  25. "status" : "Approved",
  26. "count" : 2.0
  27. }
  28. ],
  29. "staffCount" : 3.0
  30.  
  31. private List<Bson> createPipeline(String companyCode, String startDate, String endDate, String eventType, List<String> eventConfigIds, String requestType, String staffId, String status) {
  32. return Arrays.asList(
  33. match(and(getBsons(companyCode, startDate, endDate, eventConfigIds, requestType, staffId, status)
  34. )),
  35. (group("_id", createIdFields(startDate, endDate, eventType))),
  36. (group("$staffId",
  37. first("firstName", "$firstName"),
  38. first("lastName", "$lastName"),
  39. first("startDate", "$startDate"),
  40. first("endDate", "$endDate"),
  41. first("eventType", "$eventType"),
  42. first("requestType", "$requestType"),
  43. push("statuses", createPushFields()),
  44. sum("staffCount", "$count")
  45. )));
  46. }
  47.  
  48. private DBObject createPushFields() {
  49. return new BasicDBObject("status","$status").append("count","$count");
  50. }
  51.  
  52. [
  53. {
  54. "_id": "00238061",
  55. "firstName": "Kirstie Rachel Wong",
  56. "lastName": "Wong",
  57. "startDate": "2018-01-01T16:30:40Z",
  58. "endDate": "2018-12-12T16:30:40Z",
  59. "eventType": "DutySwap",
  60. "requestType": 0,
  61. "statuses": [
  62. {
  63. "status": [
  64. "Approved",
  65. "Approved",
  66. "Pending"
  67. ],
  68. "count": 3
  69. }
  70. ],
  71. "staffCount": 3
  72. }
Add Comment
Please, Sign In to add comment