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

123
Views
Add a new field in mongoDB from another collection independently?

I have two collections: profiles and contents

The profiles collection looks like this:

{
  _id: ObjectId('618ef65e5295ba3132c11111'),
  blacklist: [ObjectId('618ef65e5295ba3132c33333'), ObjectId('618ef65e5295ba3132c22222')],
  //more fields
}

The contents collection looks like this:

{
  _id: ObjectId('618ef65e5295ba3132c00000'),
  owner: ObjectId('618ef65e5295ba3132c22222'),
  //more fields
}

What I need is to get those contents where owner is not included in the blacklist. I thought about to put the blacklist field into the contents documents. I could get the profile by id separately (in another query) and set it manually in the aggregation where I get the contents, but this requires one extra connection.

So my question is: Is there a way to add my profile into each document of another collection? keep in mind that I have the profile ID.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is some psuedo code on how it "should" look like, First fetching the blacklists owners, then using that variable as a parameter in the pipeline.

const profileId = input;
const blackListIds = await db.getCollection('profiles').distinct('blacklist', { _id: profileId });
const aggregationResults = await db.getCollection('contents').aggregate([
    {
        $match: {
            owner: {$nin: blackListIds}
        }
    }
    ... continuation of pipeline ...
])
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!