var current_date = new Date().toISOString()
The toISOString() method converts a Date object into a string, using the ISO standard.
The standard is called ISO-8601 and the format is: YYYY-MM-DDTHH:mm:ss.sssZ
so when you get the current date and using this method it will not match with the existing records in database.that's why query return 0.
if you want to get the current day records you need to use following code for getting current date,month and year than use it for query.
module.exports.getOnline = async function (req, res) {
try {
var d = new Date();
var date = d.getDate();
var month = d.getMonth() + 1; // Since getMonth() returns month from 0-11 not 1-12
var year = d.getFullYear();
var dateStr = date + "/" + month + "/" + year;
const online = await Online.find({ Date: dateStr })
res.status(200).json(online.length)
} catch (e) {
errorHandler(res, e)
}
}
I think this will help you.