mongodb的联合查询
db.assets.aggregate([ {$match:{"stationId":"HNRDC"}}, {$match:{"categoryType":"TYPE_FOLDER_COMMON"}}, {$match:{"extraData.folder_used":{$gte:0}}},{ $lookup: { from: "departs", localField: "parentId", foreignField: "_id", as: "group" } }, { $unwind: { path: "$group", preserveNullAndEmptyArrays: false } }, { $project: { name:1, stationId:1, categoryType:1, "extraData.folder_used":1 } }, ]);
db.groups.aggregate([ {$match:{"stationId":"HNRDC"}}, { $lookup: { from: "mobjects", localField: "_id", foreignField: "parentId", as: "mos" } }, { $project: { name:1, stationId:1, mos: { $filter: { input: "$mos", as: "item", cond: { $eq: [ "$$item.categoryType", "TYPE_FOLDER_COMMON" ] } } } } }, { $unwind: { path: "$mos", preserveNullAndEmptyArrays: false } }, ]);