Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
why am I only able to see one side data using aggregate function in mongodb?

Image

enter image description here

As you all can see the in the image the postImage is showing Array(0), I have used the following code.

dbs.collection('posts').aggregate([
        {
            $lookup:{
                from: "images",
                localField: "_id",
                foreignField: "object_id",
                as: "postImage"
            }
        },
    ]).toArray((err, res) => {
        if(err) throw err;
        doc.send(JSON.stringify(res));
        dbs.close();
    })

Image of databse:-

post collection

enter image description here

image collection enter image description here

Here posts collections _id matches to the object_id with the images collection. I want to fetch both the data. what should I do?

Thank You in advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think so it will work after modifying code to this.

 {
  "$project": {
    "_id": {
        "$toString": "$_id"
       }
    }
 },

before using $lookup

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda