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

190
Vistas
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
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