here's my data in a mongodb document
[
{
startTime: "08:00",
endTime: "09:00",
id: 1
},
{
startTime: "08:10",
endTime: "09:00",
id: 2
},
{
startTime: "10:00",
endTime: "11:00",
id: 3
}
]
I need to find a way to get time overlapping elements using mongoose with node.js I trid using $dateFromString but no luck so far. for example item id 1 and 2 has time overlap
db.collection.aggregate([
{
$match: {}
},
{
$setWindowFields: {
partitionBy: "",
sortBy: { startTime: 1 },
output: {
previous_endTime: {
$shift: {
output: "$endTime",
by: -1,
default: "Not available"
}
}
}
}
},
{
$set: {
c: {
$cond: {
if: {
$and: [
{ $gte: [ "$previous_endTime", "$endTime" ] },
{ $gte: [ "$previous_endTime", "$startTime" ] }
]
},
then: 0,
else: 1
}
}
}
},
{
$setWindowFields: {
partitionBy: "",
sortBy: { startTime: 1 },
output: {
c: {
$sum: "$c",
window: { documents: [ "unbounded", "current" ] }
}
}
}
},
{
$group: {
_id: "$c",
c: { $sum: 1 },
id_List: { $push: "$id" }
}
},
{
$match: { c: { $gt: 1 } }
}
])