Skip to content
Advertisement

MongoDB/Mongoose – Find all where a specific Date is in a Date Range

for example I have documents with this field:

JavaScript

and I want to get all documents where a specific date (like today) is in the date range. Is it possible to make such a query? For example if I search for 18th April, then I get that document.

I thought something like this:

JavaScript

But this doesn’t work… I get an error The provided parameters were invalid. Check your query and try again.

I think new Date() is not correct in Node.js?

EDIT:

This is my Controller:

JavaScript

I exported it and here is my endpoint:

JavaScript

I tried to call this in Postman but get an empty [] back…

Advertisement

Answer

Your syntax is wrong, try this one:

JavaScript
Advertisement