How do I limit the number of returned items?

前端 未结 7 2002
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 15:32
myModel.find({}, function(err, items) {
    console.log(items.length);    // Big number
});

How can I limit the returned items to only the latest

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 16:17

    For some reason I could not get this to work with the proposed answers, but I found another variation, using select, that worked for me:

    models.Post.find().sort('-date').limit(10).select('published').exec(function(e, data){
            ...
    });
    

    Has the api perhaps changed? I am using version 3.8.19

提交回复
热议问题