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

187
Views
Mongoose hanging forever when saving document with references

My schema looks something like this:

var ZoneSchema = new Schema({
    name: String,
    coupons: [{ type: Schema.Types.ObjectId, ref: 'Coupon' }],
    magazines: [{ type: Schema.Types.ObjectId, ref: 'Magazine' }]
});

mongoose.model('Zone', ZoneSchema);

And I would then like to create a new zone like this, with the coupon and magazine arrays being empty initially:

var newZone = new Zone({
    name: req.body.name,
    coupons: [],
    magazines: []
});

newZone.save(function(err) {
    if(!err) {
        res.send({ status: 'ok', message: 'success' });
    }
    else {
        res.send(err);
    }
});

But the callback for the save function is never getting executed, and it just hangs there forever until the request just times out with no errors. This is my first time working with references in Mongoose so I'm not sure if I'm doing something wrong here. Saving using other models that don't have references works fine.

over 4 years ago · Santiago Trujillo
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!