Hello, I’m trying to make a request for my forum, I’ve worked with date for the schema.find without problem but can’t make it work with aggregate, can someone help me please ?
//Get Post Number By Category and range of Day
module.exports.postCatDate_GET = async (req, res) => {
const day = parseInt(req.query.day); // ?day=100
try {
var posts = await Post.aggregate([{
createdAt: {
"$gte": ISODate(new Date(new Date() - day * 60 * 60 * 24 * 1000)),
},
"$group": {
_id: "$categoryId",
count: {
$sum: 1
}
}
}])
res.status(200).json(posts);
} catch (err) {
res.status(500).json(err);
}
}
The group part work but I can’t add the date search like in find, I’ve read a lot about ISODate but keep the internal error.