6
在数组中的ObjectId上的$ lookup
在由ObjectId数组而不是单个ObjectId组成的字段上执行$ lookup的语法是什么? 订单文档示例: { _id: ObjectId("..."), products: [ ObjectId("..<Car ObjectId>.."), ObjectId("..<Bike ObjectId>..") ] } 不起作用的查询: db.orders.aggregate([ { $lookup: { from: "products", localField: "products", foreignField: "_id", as: "productObjects" } } ]) 所需结果 { _id: ObjectId("..."), products: [ ObjectId("..<Car ObjectId>.."), ObjectId("..<Bike ObjectId>..") ], productObjects: [ {<Car Object>}, {<Bike Object>} ], }