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

121
Vistas
Mongodb not updating the data after put request returns successful

In trying to use the objectid in the mongoose schema as a reference to do a put to update a document in a collection. The console logs its as a success but when I refresh the page or look in the mongo shell nothing changes.

Heres the put in the expressjs router:

router.put('/messageupdate/:empId', function (req, res) {
    var values = req.body;
    console.log(values);
    var empId = req.params.empId;
    console.log(empId);
    Message.update({empId: empId}, values, function(err, values) {
        if (!err) {
            res.json("okay");
        } else {
            res.write("fail");
        }
    });
})

Heres the service method:

updateServiceWithId(message: Message): Observable<any> {
 console.log(message);
    const body = JSON.stringify(message);
    console.log(body);
    const headers = new Headers({'Content-Type': 'application/json'});
    return this.http.put('http://localhost:3000/messageupdate/:empId', body, {headers: headers});

}

Heres the client side method that triggers the put:

onUpdateMessage() {
     var retVal = confirm("Do you want to continue ?");
           if( retVal == true ){
    const message = new Message(this.fname,this.lname,this.empId,this.number,this.occu);
    console.log(this.fname);console.log(this.lname);
    console.log(this.empId);console.log(this.occu);
    this.messages.push(message);
    this.messageService.updateServiceWithId(message)
        .subscribe(
            () => console.log('Success!'),
            error => console.error(error)
        );
    }
    else{
              alert("Edit cancled!");
              return false;
        }
}
about 4 years ago · Santiago Trujillo
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