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.