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

120
Views
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
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!