$matchで集計を使用できます 条件と$lookupに一致させる ローカルフィールドをマッピングするにはuser userに コレクション_id フィールド:
db.a.aggregate(
[{
$match: {
"type": ObjectId("50ed90f5a70defef23000002"),
"config.name": "alpha"
}
}, {
$lookup: {
from: "users",
localField: "user",
foreignField: "_id",
as: "users"
}
}, {
$unwind: "$users"
}]);
Javascriptでは、mongoose たとえば、これは:
YourModel.aggregate(
[{
$match: {
"type": ObjectId("50ed90f5a70defef23000002"),
"config.name": "alpha"
}
}, {
$lookup: {
from: "users",
localField: "user",
foreignField: "_id",
as: "users"
}
}, {
$unwind: "$users"
}],
function(err, result) {
console.log("lastname : " + result.users.lastname);
});