2012-11-18 64 views
8

Tôi đang cố gắng chèn bản ghi vào mongodb, bằng cách sử dụng mongoose, nhưng bản ghi không cập nhật khi bản ghi đã có trong cơ sở dữ liệu. Có điều gì tôi đang làm sai? Các tài liệu cho mongoose không phải là dễ nhất để làm theo cho tôi.Chèn/Cập nhật bản ghi bằng cách sử dụng 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'); 
      } 
     }); 

    } 
}); 

Trả lời

6

Hãy thử chuyển tùy chọn 'upsert' sang chức năng cập nhật, thay vì 'cập nhật', đây không phải là tùy chọn hợp lệ documentation.

models.fg_records.update({email:clean_email}, inactive_user, {upsert: true}, function (err) { ... }): 
Các vấn đề liên quan