Monday 29 October 2018

Update only specific field in mongodb

Hello,I am trying to update a specific field of an item in Mongodb. I am working with mongoose and have a Schema for the specific item.My patch command looks like the following: Item.update({_id: id}, { $set: {"name": req.body.name, "amount": req.body.amount, "done": req.body.done, "description": req.body.description, "unit": req.body.unit }}) After Updating for example amount with the following POST{ "done": true } All other fields not specified in the POST-Json Body getting "null"{ "_id" : ObjectId("5bd70548053851675db312c9"), "done" : true, "name" : null, "amount" : null, "description" : null, "unit" : null } What am I doing wrong? I thought the $set param would make this possible.

Submitted October 29, 2018 at 01:10PM by Sp1xx

No comments:

Post a Comment