0

In collection A, we have

"batches" : [
    ObjectId("56fccffbe7c9f9cf7634dbfe")
],

and in Collection B, we have

{ "_id" : ObjectId("56fccffbe7c9f9cf7634dbfe") }

Can we perform a lookup between these 2 collections?

1 Answer 1

1

Yes, you can use the $lookup operator as part of an aggregation, after you $unwind the batches array. For example:

db.collectionA.aggregate[

  { $unwind: "$batches" },

  { $lookup:
    from: "collectionB",
    localField: "batches",
    foreignField: "_id",
    as: "collectionB"
  }
]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.