Good mornign everyone, im trying to make a query which should return all document whithin a date range, but my query dont return document that dont exactly match the ‘llegada’ date even if they between the date range like:
intial >= intialDate || end <= endDate and also all dates inside this date range
QUERY:
db.collection.find({
$expr: {
$and: [
{
$lte: [
{
$dateFromString: {
dateString: "$llegada"
}
},
new Date("2024-06-03T06:00:00.000Z")
]
},
{
$lte: [
{
$dateFromString: {
dateString: "$salida"
}
},
new Date("2024-06-04T15:29:40.654Z")
]
}
]
}
})
And it should return all document that are valido whithin the date range but also if the ‘llegada’ Field is not equal to the instial date of the query but hits still between the dates :
EX: this documents should all be returned by the query im trying to make
Case 1
"llegada": "2024-05-31T06:00:00.000Z",
"salida": "2024-06-05T06:00:00.000Z",
Case 2
"llegada": "2024-06-03T06:00:00.000Z",
"salida": "2024-06-05T06:00:00.000Z",
Case 3
"llegada": "2024-05-27T06:00:00.000Z",
"salida": "2024-06-04T06:00:00.000Z",
How can i update my query to make this??
Thanks for your responses