Request hangs forever when saving document with references, callback never executes

20 views
Skip to first unread message

ch...@bizpub36.com

unread,
Jan 6, 2017, 11:44:46 AM1/6/17
to Mongoose Node.JS ODM
I have a schema that looks 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);

I have a request to add a new zone with the coupon and magazine arrays empty initially. The callback in the save function never executes and the request hangs forever until the client just gets a 502 error, but the server logs a 200 and doesn't crash or show any errors. The document is never saved.
exports.add = function(req, res) {
   
var newZone = new Zone({
        name
: req.body.name
   
});

   
//console.log here works fine
    console
.log('something');

    newZone
.save(function(err) {
       
//console.log here is never executed
        console
.log('something else');

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

save() works fine on models without references though.
Reply all
Reply to author
Forward
0 new messages