Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $group:
- {
- _id:'$_id.staffId',
- name: {$first: '$_id.firstName'},
- statuses:
- {
- $push:
- {
- status:'$_id.status',
- count:'$count'
- }
- },
- staffCount: {$sum: '$count'}
- }
- {
- "_id" : "00238061",
- "name" : "Kirstie Rachel Wong",
- "statuses" : [
- {
- "status" : "Pending",
- "count" : 1.0
- },
- {
- "status" : "Approved",
- "count" : 2.0
- }
- ],
- "staffCount" : 3.0
- private List<Bson> createPipeline(String companyCode, String startDate, String endDate, String eventType, List<String> eventConfigIds, String requestType, String staffId, String status) {
- return Arrays.asList(
- match(and(getBsons(companyCode, startDate, endDate, eventConfigIds, requestType, staffId, status)
- )),
- (group("_id", createIdFields(startDate, endDate, eventType))),
- (group("$staffId",
- first("firstName", "$firstName"),
- first("lastName", "$lastName"),
- first("startDate", "$startDate"),
- first("endDate", "$endDate"),
- first("eventType", "$eventType"),
- first("requestType", "$requestType"),
- push("statuses", createPushFields()),
- sum("staffCount", "$count")
- )));
- }
- private DBObject createPushFields() {
- return new BasicDBObject("status","$status").append("count","$count");
- }
- [
- {
- "_id": "00238061",
- "firstName": "Kirstie Rachel Wong",
- "lastName": "Wong",
- "startDate": "2018-01-01T16:30:40Z",
- "endDate": "2018-12-12T16:30:40Z",
- "eventType": "DutySwap",
- "requestType": 0,
- "statuses": [
- {
- "status": [
- "Approved",
- "Approved",
- "Pending"
- ],
- "count": 3
- }
- ],
- "staffCount": 3
- }
Add Comment
Please, Sign In to add comment