$lookup with local Field and foreign Field in not working in azure cosmos dB

how to use when receiving data in body in localfield and foreignfield.
how to use _id after $match condition in localfield

const fetchData = await WorkflowModel.aggregate([
        $match: {
          _id: mongoose.Types.ObjectId(req.body.workflow_id),
        $unwind: "$_id",
        $lookup: {
            from: "tasks",
            localField: "_id",
            as: "task"

you do not need to unwind

Hi @Avish_Pratap_Singh,

What error message or outcomes are you seeing? Can you share some sample documents to test with?

As @steevej mentioned, you do not need to $unwind the _id field as it cannot be an array. I’m not sure about Cosmos’ implementation, but in genuine MongoDB you also don’t need to $unwind even if the localField is an array (see Use $lookup with an Array).


1 Like