I'm attempting to create a mongo query that retrieves all active listings based on the current date
{
$and: [
{
start_time: {
$lte: {
$currentDate: {
$type: "date"
}
}
}
},
{
end_time: {
$gte: {
$currentDate: {
$type: "date"
}
}
}
}
]
}
However, this query returns nothing. If I change end_time:{$gte
to {$lte
, all listings are displayed, indicating there may be an issue.
I'm adding the dates to the database using JavaScript
if (checked) {
var d = new Date()
d.setSeconds(d.getSeconds() + values.sale_price * 100)
setFieldValue('start_time', { date: new Date() })
setFieldValue('end_time', { date: d })
}
I suspect the problem may arise when adding seconds to the end time, but I'm not certain
Here is a sample document from the database
{
"_id": {
"$oid":"61401b66t4e445t5j43j748e"
},
"name": "test",
"sale_price": {
"$numberInt": "5000"
},
"start_time": {
"date": "2021-09-14T03:47:31.918Z"
},
"end_time":{
"date": "2021-09-19T22:40:51.918Z"
}
}