我想限制由Model.find()MongoDB中返回的數據長度的數據/貓鼬限制由model.find()返回在MongoDB中
這裏是我的代碼 想從返回「摘錄」內容。
Blog.find({},{
title: 1,
content: 1 // basically wants to return content not more than 200 character
}, function(err, data){
if (err) {
console.log(err);
}
res.render('blog/posts', {
title:'All posts',
posts: data
});
});
換句話說如何從MongoDB的
更新 返回有限的內容中找到解決方案:
Match with substring in mongodb aggregation
你試過用'filter' https://docs.mongodb.com/manual/reference/operator/aggregation/filter/ –
過濾器返回滿足一定條件的文檔,但是我想返回所有文檔,但是分片>>例如。如果文檔有像'這是非常長的文本顯示'的條目,我想只返回'這是非常..' –
[與MongoDB聚合中的子字符匹配]的可能重複(http://stackoverflow.com/questions/20066279/match-with-substring-in-mongodb-aggregation) –