Thursday 15 March 2012

node.js - Update a record where _id = :id with Mongoose -


I am trying to update an existing record with Mongoos. This entry is okay, but there is no update.

This is my snippet:

  ap. Post ('/ submit', function (req, res) {var my_visit = new model. Visits ({date: req .one.visit_date, type: req.body.visit_type, agency: req.body.visit_agency, city: req.body.visitude, url: req.body.visit_url, note: rake.body.visit_note}); // INSERT If (req.body.id == 0) {my_visit.save (function (error) {if} {throw error;} console.log ('added travel'); res .redirect ('/'); });} And {// UPDATE var upsertData = my_visit.toObject (); console.log (req.body.id); // OK Model. Visit.update ({_id: req (error); console.log ( 'Updated travel:' + req.body.id); res.redirect ('/');});}})   

The response is mod_id_id's Un Mati is not .

I just want to update the line in MySQL like WHERE id = id I did not get the correct syntax.

And according to, mod _id

I also found that Attempts to explain a solution clearly states:

Do not use existing model examples for the updated section (this will not work and cause strange behaviors such as infinite loop ). Also, make sure that there is no _ID property in the update section, so that Mongo returns "_id not allowed" on the modid "error.

Such a solution, looks like the following:

  var upsertData = my_visit.toObject (); Console.log (req.body.id); // Delete the upstate data right away; _id; Models.visits.update ({_id: req.body.id}, upsertData, {multiple: wrong}, function (mistake) {if (err) {throw error;} // ...}   

On one side of the note, you can probably repeat your route again if both create and update without the second block. An additional option takes upsert According to which the docs:

is the upstate (boolean) to make a doctor if it does not match (false)

No comments:

Post a Comment