2012-11-18 5 views
8

mongooseを使用してmongodbにレコードを挿入しようとしていますが、レコードがデータベースにすでに存在する場合はレコードが更新されません。私が間違っていることはありますか? mongooseのドキュメントは、私のために従うのが一番簡単ではありません。mongooseを使用したレコードの挿入/更新

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'); 
      } 
     }); 

    } 
}); 

答えて

6

ではなく、有効なオプションdocumentationではありません「更新」、の、更新機能にオプション「アップサート」を渡して試してみてください。

models.fg_records.update({email:clean_email}, inactive_user, {upsert: true}, function (err) { ... }): 
関連する問題