need Mongoose Model.find() to work when queries aren’t present

I’m currently working on the freeCodeCamp Exercise Tracker Project on Replit.
my Project Link: https://replit.com/@mazorSharp/Exercise-Tracker?v=1
If you click on the link, the code I’m referring to is in the server.js file and It’s the code under the comment labeled // NUMBER 3

I’m running into an issue with one of the GET routes.
GET user’s exercise log: GET /api/users/:_id/logs?[from][&to][&limit]

The GET route works fine when all queries are used in the get search. Queries for the test are From, To, and Limit. If one of the queries aren’t present in the GET request I get an error.

CastError: Cast to date failed for value “Invalid Date” (type Date) at path “date” for model “exerciseInfo”

What steps would I need to take to make sure if someone isn’t putting in values for FROM, TO, and LIMIT queries that it wouldn’t throw an error because of it?

app.get('/api/users/:_id/logs', (req, res) => {

  const {from, to, limit} = req.query;
  let idJson = {"id": req.params._id}
  let idToCheck = idJson.id;

  console.log("from=> ", from, "to=> ", to, "limit=> ", limit, "idToCheck=> ", idToCheck);

  //Check ID
  ExerciseInfo.findById(idToCheck, (err, data) => {
if (err) {
  console.log("Error with ID => ", err);  
} else {

  // Find Username Documents
  ExerciseInfo.find(({username: data.username}, {date: {$gte: new Date(from), $lte: new Date(to)}}), null , {limit: +limit} , (err, doc) => {
    let loggedArray = []
    if (err) {
      console.log("error with username=> ", err);
    } else {

      console.log("all docs related to username=> ", doc);
      let documents = doc;
      let loggedArray = documents.map((item) => {
        return {
          "description": item.description,
          "duration": item.duration,
          "date": item.date.toDateString(),
        }
      })
      
      const test = new LogInfo({
        // "_id": idToCheck,
        "username": data.username,
        "from": from,
        "to": to,
        "count": limit,
        "log": loggedArray,
      })

      test.save((err, data) => {
        if (err) {
          console.log(err);
        } else {
          console.log("saved exercise successfully")
          res.json({
            "_id": idToCheck,                
            "username": data.username,                
            "from": data.from.toDateString(),
            "to": data.to.toDateString(),
            "count": data.count,
            "log": loggedArray,
          })
        }
      })  
    }
  })
}

})
})