I am trying to query a date field (deadline) using the following query but it returns an empty list. We expect it to return some values in the list. Is this the right way to query on a date field?
Moralis.Cloud.define("filterJobsNew", async (request) => {
const query = new Moralis.Query("Job");
logger.info(`lower bound date ${request.params.deadlineFilter[0]}`);
logger.info(`upper bound date ${request.params.deadlineFilter[1]}`);
let sortOrder = 1;
if (request.params.sortOrder === "desc") {
sortOrder = -1;
}
const pipelineWithJobType = [
{
match: {
$expr: {
$and: [
{ $eq: ["$status", 0] },
{ $gte: ["$desiredMinLockedStake", request.params.lockedStake[0]] },
{ $lte: ["$desiredMinLockedStake", request.params.lockedStake[1]] },
{
$gte: ["$deadline", new Date(request.params.deadlineFilter[0])],
},
{
$lte: ["$deadline", new Date(request.params.deadlineFilter[1])],
},
{ $in: ["$type", request.params.jobType] },
],
},
},
},
{
lookup: {
from: "UserInfo",
localField: "clientUsername",
foreignField: "spectUsername",
as: "user",
},
},
{
sort: {
[request.params.sortBy]: sortOrder,
},
},
];
return await query.aggregate(pipelineWithJobType);
});
Here is the request params being sent -
Input: {"ethAddress":"0x92d202402068108f3301e3c0bcf8b77f4a94a2a7","mainFilter":"all","jobType":[],"lockedStake":[0,9007199254740991],"deadlineFilter":["2021-10-04T17:56:55.080Z","2022-10-04T17:56:55.080Z"],"sortBy":"desiredMaxPrice","sortOrder":"desc"}