Hello, I have a query that produces an output like so:
[
{
"firstName": "pete",
"lastName": "smith",
"eventDate" : "2020-01-27T18:20:50.497Z"
},{
"firstName": "pete",
"lastName": "smith",
"eventDate" : "2020-01-27T17:21:50.497Z"
},{
"firstName": "pete",
"lastName": "smith",
"eventDate" : "2020-01-27T18:11:50.497Z"
},{
"firstName": "mark",
"lastName": "johnson",
"eventDate" : "2020-01-27T18:26:50.497Z"
},{
"firstName": "carlos",
"lastName": "santana",
"eventDate" : "2020-01-27T18:21:50.497Z"
}
]
I would like to transform that output in a way where it would consolidate the objects with the same firstName and last names and aggregate their dates into something such as an average date, (or array of diferent dates) since right now I have duplicated records I would not like to be there.
So anything like this:
[
{
"firstName": "pete",
"lastName": "smith",
"eventDate" : ["2020-01-27T18:20:50.497Z", "2020-01-27T17:21:50.497Z", "2020-01-27T18:11:50.497Z"]
{
"firstName": "mark",
"lastName": "johnson",
"eventDate" : ["2020-01-27T18:26:50.497Z"]
},{
"firstName": "carlos",
"lastName": "santana",
"eventDate" :[ "2020-01-27T18:21:50.497Z"]
}
]
or this:
[
{
"firstName": "pete",
"lastName": "smith",
"eventDate" : "2020-01-27T18:20:50.497Z" <-where these are avgs
{
"firstName": "mark",
"lastName": "johnson",
"eventDate" : "2020-01-27T18:26:50.497Z"<-where these are avgs
},{
"firstName": "carlos",
"lastName": "santana",
"eventDate" : "2020-01-27T18:21:50.497Z"<-where these are avgs
}
]
would work for me.
Could anyone assist with this?