How do I limit the number of returned items?

前端 未结 7 1956
没有蜡笔的小新
没有蜡笔的小新 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:00

    models.Post.find({published: true}, {sort: {'date': -1}, limit: 20}, function(err, posts) {
     // `posts` with sorted length of 20
    });
    

提交回复
热议问题