mongoose - Mongodb aggregation lookup record limit -
i have function in moongose+mongodb:
blog.aggregate([{ "$match": {"user_id": userblog}}, { "$lookup": { from: "comments", // collection name in db localfield: "_id", foreignfield: "blogid", as: "comments" }, }]).exec(function(err, docs) { });
this works perfectly, how limit comments , retrive last 10 records? thank's lot. marco.
add limit code
blog.aggregate([{ "$match": {"user_id": userblog}}, { "$lookup": { from: "comments", // collection name in db localfield: "_id", foreignfield: "blogid", as: "comments" } }]).limit(10).exec(function(err, docs) { });
Comments
Post a Comment