$gte and $lte doesn't with variable

I want to initialize variable in the beginning by date than change the variable with the date comes from the request for example :

 startDate = new Date('2022-01-01');
    endDate = new Date();
return this.dataModel.aggregate([
$match: { $gte:startDate,$lte:endDate }

I got only data with matched date initialized in startDate endDate
If I console the passed data in the request it shows what I put in startDate endDate
any help please

Can you explain what is getting returned, or the error you get, when this query runs? I’m not a NodeJS developer, but this doesn’t look like a valid query to me. From the looks of things I would think you would get an error as it looks like you’re missing a field to match on.

1 Like

Your match statement needs the field names.

1 Like

I solved this by initiate variables in front side