Mongoose Limit Error - Help

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 :+1:

@bstefansen Make sure you convert limited to a number or you will have trouble.

1 Like

Dammit! It’s always something so simple. Thank you sir!!! You’re a gentleman and a scholar :+1: