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

88
Views
set field for docs in one collection based on ref to another collection

I have todo schema and actions schema. Each todo is made up of actions. My todos already have a field for 'subject'.

Question: How do I update the actions so that their 'subject' field equals a given 'subject' field fro the referenced todo?

const todo = new Schema({
  subject: String,
  actions: { type: Schema.Types.ObjectId, ref: 'Action' },


})
const action = new Schema({
  action: String ,
  todoID: { type: Schema.Types.ObjectId, ref: 'Todo' },
  subject: String //needs to be populated

})

*I want to avoid doing something like this: Action.find().forEach(action=>{ todo.findByID(action.todoID) .then(yadda yadda) .catch(not what I want to do) })

I feel like there is an aggregation solution but I cant figure this out.

Thank you.

about 4 years ago · Juan Pablo Isaza
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!