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 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.query.limit;
      .find({ userid: req.userId }, (err, dataExercise) => {
        req.dataExercise = dataExercise;
  // TODO: limit not working
  (req, res, next) => {
    userModel.findOne({ _id: req.userId }, (err, dataUser) => {
        username: dataUser.username,
        count: req.dataExercise.length,
        log: req.dataExercise

Project Code:!/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:

May I ask why you are using the limit method?

Never mind. I see now from the sample project.

1 Like

FYI - You will notice the sample project is using a querystring like:


and then using querystring parameters like limit=3

1 Like