Reputation: 568
I am trying to update a record from mongoDB collection using Postman.
This is the code I am using to do it.
// Update message with id (using a PUT at http://localhost:8080/messages/:message_id)
router.route('/messages/:message_id')
.put(function(req, res) {
Message.findById(req.params.message_id, function(err, message) {
if (err)
res.send(err);
// Update the message text
message.text = req.body.text;
message.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Message successfully updated!' });
});
});
});
//Updating A Message end.
Next, this is the URI I am typing in Postman to update (based on the id key): localhost:8080/messages/ObjectId("58ab37f9d23f991791490963")
Then I get this error message:
I am trying to commit to a Bitbucket repository. What should I change in the URI to make the update valid?
Upvotes: 0
Views: 1076
Reputation: 2636
You may want to drop the ObjectId
part from what you are posting and just send the id itself then create an ObjectId on the server
localhost:8080/messages/58ab37f9d23f991791490963
router.route('/messages/:message_id')
.put(function(req, res) {
var id = new ObjectId(req.params.message_id)
Message.findById(id, function(err, message) {
...
})
Upvotes: 1