【发布时间】:2016-01-24 13:12:51
【问题描述】:
让我使用以下伪示例来更好地解释我的需求。
我有一群人和一些属于组模式的图像
{
images:['ARRAY OF IMAGES'],
members:[{
age:NUMBER,
name:STRING,
email:EMAIL_OF_MEMBER
}],
groupName:String
....etc
}
现在我有一个聚合查询
group.aggregate([
{
$project:{
//some code happening to support query in the below $match
'original':$$ROOT
}
},
{
$match:{//some query code happening and all params from $project above will be available here. the $original field contains all fields of document}
},
{
//Now i want to extract 1st image from Images array, Min and Max age of members in group.
}
],function(err,results){//dosomething with results})
如果我不使用第三个管道,我将获得我不需要的整个文档。我只需要一组人的 1 张图片和最小最大年龄来显示网页。我不需要其他细节。
【问题讨论】:
标签: arrays mongodb mongoose mongodb-query