Insert / Update Recording Using Mongoose

I am trying to insert a record in mongodb using mongoose, but the record is not updated when the record is already in the database. Is there something I'm doing wrong? The documentation for the mongoose is not the easiest for me.

models.fg_records.update({email:clean_email}, inactive_user, {update: true}, function (err) { if(err){ throw err; console.log(err); } else { // send mail with defined transport object transport.sendMail(message, function(err, response) { if(err) { console.log(err); view('<ul><li>There was a problem sending an email to this user. Make sure you types it correctly.</li></ul>'); } else { res.redirect('/records'); } }); } }); 
+8
mongoose
source share
1 answer

Try passing the "upsert" option to the update function instead of "update", which is not a valid documentation option.

 models.fg_records.update({email:clean_email}, inactive_user, {upsert: true}, function (err) { ... }): 
+6
source share

All Articles