Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
Mongo DB not updating, without error

Trying to update the below M Lab hosted mongo DB, not much luck, any ideas? Form input via handlebars template, routed to express server. No errors, and DB does not update.

{ "_id": { "$oid": "58fdec20a8aac60a190152ae" }, "name": "Item1", "status": 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 Respuestas
Responde la pregunta

0

Please make callback function out of $set braces just like this:

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 Denunciar

0

Using mongojs below was my solution.

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda