Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda