Hello there, I have been working on the exercise tracker and I have come to the last test. My problem is that where().gte().lte().limit() sequence doesn’t work. And It worked before but I was using another model for exercise log then I merged both models in one and now this sequence is not working. I think the problem is lying with locating “log.date” with where() because sort() is also not working but I couldn’t find any solutions to solve it.
Also I know if statement should set rules for From and To too, but I will come to that once I manage to make this work first.
If necessary, here is my glitch link: https://glitch.com/edit/#!/calm-fcc-exercise-tracker
Also, I only have been learning JavaScript for two months and I started node last week, so if you have any suggestions regarding the entirety of the code, you are very welcome.
app.get("/api/exercise/log", function(req, res) {
var id = req.query.userId;
if (req.query.limit) {
var from = req.query.from;
var to = req.query.to;
var limit = req.query.limit;
console.log(from, to, limit);
Workout.find({ _id:id })
.sort({"log.date":-1})
.where("log.date")
.gte(new Date(from).toDateString()) //new Date(from).toDateString())
.lte(new Date(to).toDateString())
.limit(Number(limit))
.select("-userId -log._id -__v")
.exec(function(err, data) {
if (err) return console.error(err);
console.log(data)
res.json(data[0]);
});
} else {
Workout.find({ _id: id })
.select("-userId -log._id -__v")
.exec(function(err, data) {
if (err) return console.error(err);
res.json(data[0]);
});
}
});