mongodb之lookup单条件关联
select * from MiscShipRecord left join DeliveryRecord on MiscShipRecord._id=new ObjectId(DeliveryRecord.SourceEntityID)
Mongodb实现方式:
db.MiscShipRecord.aggregate([ { $match : { _id : new ObjectId("62fb05d7e4ca8700257fad96") } }, // where MiscShipRecord._id=new ObjectId("62fb05d7e4ca8700257fad96") { $addFields: { "MiscShipRecordId": { "$toString": "$_id" }}}, // toString(MiscShipRecord._id) as MiscShipRecordId { $lookup: { from: "DeliveryRecord", localField: "MiscShipRecordId", foreignField: "SourceEntityID", as: "DeliveryRecord_docs" } }, // DeliveryRecord.SourceEntityID=MiscShipRecordId { $unwind: "$DeliveryRecord_docs" // 展开 } ])