1

I have one table membership and another is promo codes.

membership table:

/* 1 */
{
    "_id" : ObjectId("5b62e7050b13587e9febb8db"),
    "country_id" : "5a093507f1d45633844096ef",
    "type" : "Bronze",
    "price" : "30",
}
/* 2 */
{
    "_id" : ObjectId("5b6961175140b477032291b7"),
    "country_id" : "5a093507f1d45633844096ef",
    "type" : "Gold",
    "price" : "1000",
}....

promo code table :

{
    "_id" : ObjectId("5cfe23fd075be65883f6d921"),
    "final_status" : 1,
    "membership" : [ 
        ObjectId("5b62e7050b13587e9febb8db"), 
        ObjectId("5b6961175140b477032291b7"), 
        ObjectId("5b6961285140b477032291b8"), 
        ObjectId("5b7567dd5b874856981b53d3"), 
        ObjectId("5bba1c3794c6761db256edbc")
    ],
    "month" : [ 
        "1", 
        "3"
    ]
}

here, the promomcode table has a membership id. I want promo code data with membership join query.get promo code data with membership detail Please help me

1

1 Answer 1

1

Use $lookup for left outer join in mongodb

db.promocode.aggregate([{
  $lookup: {
    from: 'membership',
    localField: 'membership',
    foreignField: '_id',
    as: 'memberships'
  }
}, {
  $project: {
    membership: 0
  }
}])

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.