db.order_list.aggregate([
{
$unwind: “$booklist”
},
{
$lookup: {
from: “contents”,
localField: “booklist.isbn”,
foreignField: “isbn”,
as: “xxxx”
}
},
{
$group:{
_id:{order_no:”$order_no”},
booklist:{
$push:”$xxxx.isbn”,
$push:”$xxxx.title”
}
}
}

])

 

======================================

 

 

db.votes.aggregate([
{
$lookup: {
from: “users”,
localField: “createdBy”,
foreignField: “_id”,
as: “userYYY”
}
},
{
$unwind: “$userYYY”
},
{
$unwind: “$userYYY.emails”
},
{
$sort: { “userYYY.emails.verified”: -1 }
},
{
$group: {
_id: “$_id”,
createdBy: { $first: “$createdBy” },
fellowIdXXX: { $first: “$fellowId” },
companyId: { $first: “$companyId” },
teamId: { $first: “$teamId” },
userXXX: { $first: “$userYYY” }
}
},
{
$lookup: {
from: “fellows”,
localField: “fellowIdXXX”,
foreignField: “_id”,
as: “fellow”
}
},
{
$unwind: “$fellow”
},
{
$lookup: {
from: “companies”,
localField: “companyId”,
foreignField: “_id”,
as: “company”
}
},
{
$unwind: “$company”
},
{
$lookup: {
from: “teams”,
localField: “teamId”,
foreignField: “_id”,
as: “team”
}
},
{
$unwind: “$team”
},
{
$project: {
“_id”: 1,
“firtNames”: “$userXXX.profile.name.first”,
“lastName”: “$userXXX.profile.name.last”,
“emailAddress”: “$userXXX.emails.address”,
“companyTitle”: “$company._id”,
“teamTitle”: “$team._id”,
“fellowTitle”: “$fellow._id”,
“isVerified”: “$userXXX.emails.verified”
}
}

,
{
$group: {
_id: “$_id”,
createdBy: { $first: “$createdBy” },
fellowIdXXX: { $first: “$fellowId” },
companyId: { $first: “$companyId” },
teamId: { $first: “$teamId” },
userXXX: { $first: “$userYYY” }
}
}

])