I’ve been working on agregation in the past days but I could not figure out how to filter documents with the same dates.
Here are the documents. At the moment, there are 5 of them.
Index 0
and index 1
has the same date and Index 2
and index 3
has the same date
The idea is, filter those documents with the same date and total the start
and end
on each filtered objects
Here is the full exported documents from the mongodb
[
{
_id: "63df0b216557e49cd48d0399",
start: "2023-02-05T01:49:21.677Z",
isWorking: false,
createdAt: "2023-02-05T01:49:21.789Z",
updatedAt: "2023-02-05T01:49:28.109Z",
end: "2023-02-05T01:49:28.010Z",
},
{
_id: "63df0ad16557e49cd48d0390",
start: "2023-02-05T01:48:01.843Z",
isWorking: false,
createdAt: "2023-02-05T01:48:01.936Z",
updatedAt: "2023-02-05T01:48:06.355Z",
end: "2023-02-05T01:48:06.272Z",
},
{
_id: "63df0d1d47e5e303ef3f1987",
start: "2023-02-04T01:57:08.230Z",
isWorking: false,
createdAt: "2023-02-04T01:57:08.230Z",
updatedAt: "2023-02-04T01:57:08.230Z",
end: "2023-02-04T01:57:42.900Z",
},
{
_id: "63df0cc247e5e303ef3f1986",
start: "2023-02-04T01:55:15.091Z",
isWorking: false,
createdAt: "2023-02-04T01:55:15.091Z",
updatedAt: "2023-02-04T01:55:15.091Z",
end: "2023-02-04T01:56:12.035Z",
},
{
_id: "63df0d5147e5e303ef3f1988",
start: "2023-02-03T01:58:18.018Z",
isWorking: false,
createdAt: "2023-02-03T01:58:18.018Z",
updatedAt: "2023-02-03T01:58:18.018Z",
end: "2023-02-03T01:58:35.941Z",
},
];
2
Answers
After reading the documentation and watching a lot of tutorials, I think I solved it but I won't mark this as an answer yet because I know there will be some edits for this solution.
This is the result.
You can use
Set
to avoid duplicate datas.Get additional information about
Sets
from here.