$group-stadiet har følgende prototypeform:
{ $gruppe:{ _id:, :{ : }, ... } }
Dit felt1 er Timer og akkumulator1 er sum ,Derfor bør din aggregering være sådan her:
db.pms_teamleadtimesheets.aggregate( // Pipeline [ // Stage 1 { $match:{ UserName:"Admin", FacilityID:"59a53f0c6077b2a029c52b7f", ProjectID:"5a042ba02af18ac8388}, {2} $group:{ _id:{ ProjectID:"$ProjectID", Opgave:"$Text", Phase:"$phase", Kommentarer:"$Comments", TaskType:"$TaskType", Items:"$Items", UserName :"$UserName", IsBillable:"$IsBillable", Dato:"$StartDate" }, Timer:{$sum:"$Hours" } } }, // Trin 3 { $project:{ _id:0, ProjectID:"$_id.ProjectID", Phase:"$_id.Phase", Opgave:"$_id.Task", Kommentarer:"$_id.Comments", TaskType:"$_id.TaskType", Items:"$_id.Items ", Brugernavn:"$_id.UserName", IsBillable:"$_id.IsBillable", Dato:"$_id.Date", Timer:{ $divide:[ "$Hours", 60 ] } } }, ]);
Output for med de givne testdata:
{ "ProjectID" :"5a042ba02af18ac8388bd3c0", "Phase" :"Analyse", "Task" :"Analyse", "Kommentarer" :"2", "TaskType" :"LEVERINGS", "Elementer" :"CRI", "UserName" :"Admin", "IsBillable" :true, "Date" :"29-05-2018", "Hours" :4.0}{ "ProjectID" :"5a042ba02af18ac8388bd3c0", "Phase" :"Analysis", "Task" :"Analyse", "Comments" :"8", "TaskType" :"DELIVERY", "Items" :"Andre", "UserName" :"Admin", "IsBillable" :true, "Dato" :"28-05-2018", "Timer" :4.0}{ "ProjectID" :"5a042ba02af18ac8388bd3c0", "Phase" :"Analyse", "Opgave" :"Analyse", "Kommentarer" :"4" , "TaskType" :"LEVERINGS", "Items" :"Andre", "UserName" :"Admin", "IsBillable" :true, "Dato" :"28-05-2018", "Timer" :4.0}
Læs mere her