Tell us what’s happening:
I am trying to use slice() to limit my exercises array based on the limit query string, and I believe I am following the correct syntax, but I get this error:
Invalid $slice syntax. The given syntax { $slice: “5” } did not match the find() syntax because :: Location31273: $slice only supports numbers and [skip, limit] arrays :: The given syntax did not match the expression $slice syntax. :: caused by :: Expression $slice takes at least 2 arguments, and at most 3, but 1 were passed in.
Here is the line of code where I am clearly passing in 2 arguments- ‘exercises’ and the limit.
User.findOne({_id: req.params._id}).slice(‘exercises’,limit).exec(function(err, data){
In the above code in your Replit, the variable limit is of type string. The slice() method in your following code is expecting a number. That might be the cause of the error.