Anyone know why the limited variable is not working? When I pass a number, it works, but when I pass the req.limited variable, I get an error about the req.dataExercise.length.
// GET user log
app.use("/api/exercise/log?", (req, res, next) => {
req.userId = req.query.userId;
req.limited = req.query.limit;
exerciseModel
.find({ userid: req.userId }, (err, dataExercise) => {
req.dataExercise = dataExercise;
next();
})
.limit(3);
// TODO: limit not working
},
(req, res, next) => {
userModel.findOne({ _id: req.userId }, (err, dataUser) => {
res.json({
username: dataUser.username,
count: req.dataExercise.length,
log: req.dataExercise
});
});
}
);
Project Code: https://glitch.com/edit/#!/exercise-tracker-stefansen
Thank you!
Cheers