Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
create an get api in nodejs to join two collection based on Id like a left join

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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();
    }
);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!