Let me use following pseudo example to better explain my need.
I have a group of people and some images which belong to group schema
{
images:['ARRAY OF IMAGES'],
members:[{
age:NUMBER,
name:STRING,
email:EMAIL_OF_MEMBER
}],
groupName:String
....etc
}
Now i have a aggregation query
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})
If I don't use 3rd pipeline I am getting the whole document which is not required for me. I just need 1 image and min-max age of people in group to display a web page. I don't need other details.