Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
Mongo DB no se actualiza, sin error

Intentando actualizar la base de datos mongo alojada por M Lab a continuación, no tuve mucha suerte, ¿alguna idea? Entrada de formulario a través de la plantilla del manillar, enrutada al servidor express. No hay errores y la base de datos no se actualiza.

{ "_id": { "$oid": "58fdec20a8aac60a190152ae" }, "nombre": "Artículo1", "estado": 0 }

 app.put("/:id", function(req, res) { db.collection.update({_id: req.body.id}, { $set:{status: 1}, function(){ res.redirect("/"); console.log('updated') } }); });
 <ul> Let's Eat {{#each ndev}} <li> <p> <form action="/:{{this._id}}?_method=PUT" method="POST"> <input type="hidden" name="id" value="{{_id}}">{{name}} <button type="submit">Update</button> </form> </p> </li> {{/each}} </ul>

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Realice la función de devolución de llamada con $set llaves como esta:

 app.put("/:id", function(req, res) { db.collection.update({_id: req.body.id},{$set:{status: 1}}, function(err,doc) { if(err){ console.log(err); } res.redirect("/"); console.log('updated') }); });
about 4 years ago · Santiago Trujillo Report

0

Usar mongojs a continuación fue mi solución.

 app.put("/:id", function(req, res) { var id = req.body.id; db.collection.findAndModify({ query: { _id: mongojs.ObjectId(id)}, update: { $set: {status: 1}}, new: true}, function(err, doc, collection){ if(err){ res.send(err); }else{ res.redirect("/"); } }); });

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!