brucelee
brucelee

Reputation: 147

Mongoose limiting queries doesn't work

I want to limit my results

    items.find(function(err, theItems){
        if(err) res.send(err)
        res.json(theItems);
    });

I searched and I should do .limit and with certain versions it should be combined with sort and exec etc etc.

However it's not working. I just can't find an answer on something simple like this :/

Also, out of all the documentation that I've been reading and learning from for the past 2 months, mongoose's is by far the most difficult to understand. Is there a good place somewhere to learn mongoose from ??

Upvotes: 0

Views: 901

Answers (1)

jtmarmon
jtmarmon

Reputation: 6179

In the future you should show the code that isn't working so we can help diagnose the issue.

in mongoose you chain together parts of the query until you're ready to execute it. you can do:

items.find().sort({field: 1}).limit(5).exec(function(err, theItems) ...

Upvotes: 3

Related Questions