I have created a time entry system in which users can enter in the amount of time (percentage) spent on a task between a given time period. Each record looks like the following. I changed the user _id to explicit names to make it easier to visualize
"project_name": "first_project",
"linked_project": "5bd057f5d4b8173d88b7fe47",
"percentage": 25,
"user": {
"$oid": "Steve"
},
"project_name": "first_project",
"linked_project": "5bd057f5d4b8173d88b7fe47",
"percentage": 50,
"user": {
"$oid": "Steve"
},
"project_name": "second_project",
"linked_project": "5bd057f5d4b8173d88b7fe48",
"percentage": 25,
"user": {
"$oid": "Steve"
},
"project_name": "second_project",
"linked_project": "5bd057f5d4b8173d88b7fe48",
"percentage": 75,
"user": {
"$oid": "Mary"
},
I'm trying to first group by Person and then by project. Basically I want a total of how much each user has spent on a particular task. Not sure if what I am trying to achieve is even possible. I have included what I am trying to achieve below:
Example output:
[
{
user: Steve,
projects: [
first_project: 75,
second_project: 25
]
},
{
user: Mary,
projects: [
second_project: 75
]
}
]
I've tried a variety of ways to achieve this and I haven't come close. Hopefully someone has some insight on how to achieve this.