I'm running the following code which returns many results. I want to limit the results to the first 10 docs. How can I add a "limit" to the following mongoose query?
var reg = new RegExp('^'+id,'i');
models.examples.distinct('myId', {myId: reg}, function(err, docs) {
console.log("docs: " + util.inspect(docs));
res.send(docs);
});
Currently you cant call limit on distinct - please vote for: SERVER-2130.
You could utilise the aggregation framework to limit the number returned over the wire, by doing a $group and then a $limit.