Exercise Tracker - Date Range

Hello,
I have spent nights on this and I would be very grateful if anyone could relieve me of this stress :sob:. I’m working on the exercise tracker and I’m stuck on getting the user’s log within a certain range. This is my code so far.

app.get('/api/exercise/log',function(req,res){
  console.log('Call Starts');
  console.log(req.query.limit || parseInt(req.query.limit));
  let from=req.query.from? new Date(req.query.from).getTime() : new Date('1994-01-01').getTime();
  let to=req.query.to? new Date(req.query.to).getTime() : new Date().getTime();
  Exercise.findOne({userId:req.query.userId ,log:{date:{$gte:from,$lte:to}}},function(err,exercises){
   if(err) return console.log(err);
    console.log('Called Exercises ');
   User.findOne({_id:req.query.userId},function(err,user){
     if(err) return console.log(err);
     console.log('Called Users ');
     res.json({
       _id:req.query.userId,
       username:user.username,
       count:exercises.log.length,
       log:exercises.log
     });
   });
  });
});

This is the data I’m working with

{"_id":"5dfa6e23ef4b260e8c23a70c",
"username":"bolton",
"count":4,
"log":[
{"description":"Eat sandwich","duration":30,"date":1576454400000,"_id":"5dfa6e49ef4b260e8c23a70e"},
{"description":"Eat sandwich","duration":300,"date":1576454400000,"_id":"5dfa6f1c2924c010b35c6b60"},
{"description":"Eat sandwich","duration":400,"date":1576454400000,"_id":"5dfa6f3a2924c010b35c6b61"},
{"description":"Eat sandwich","duration":400,"date":1576454400000,"_id":"5dfa6f702924c010b35c6b62"}]}

This is the error I get

 message: 'Cast to number failed for value "{ \'$gte\': 757382400000, \'$lte\': 1576694697640 }" at path "date"',

Thanks in advance.

Hey! did you find out what was wrong? I have been breaking my head on this for almost 5 days now with no help :expressionless:

In my case it says "Cast to DATE failed…’

I found the exact problem with somebody on

sadly an answer is very difficult to find