I had two collection I want to perform a kind of left join but want to perform through a router API. I am new to node js. Can you please help me in it.
For me you have three solutions:
1) Code it yourself with Javascript and doing one function with two Api calls (not good at all)
2) You have the lookup solution which is detailed in this other post (seems the right solution)
EDIT:
3) The third solution is also in the same post and it looks like this : (what most people are doing but as optimized as option 2), it is not exactly the solution you want since it it doesnt merge both collections at once, but you end up with the same kind of data that you wanted
db.collection1.find().forEach(
function (document) {
document.collection2 = db.collection2.find( { "collection1": document._id } ).toArray();
document.collection3 = db.collection3.find( { "_id": { $in: document.collection3 } } ).toArray();
}
);