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

147
Views
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 answers
Answer question

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 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!