I am updating a document in projects
collection. which looks like below:
projects collection
"_id" : ObjectId("5c2df5ccfb98b328c470597b"),
"clientName" : "abc",
"attachments" : [],
"status" : "ongoing",
"assignId" : ObjectId("5c2df3c3fb98b328c4705979"),
"upworkId" : ObjectId("5c2df956b84e902678f416fa")
Now, I am getting upworkId field null or empty from client side, But getting the new value for clientName
, status
and attachments
. So i want to remove the upworkId
field and update the other field values in project collection. How can i?
My current update query is:
Project.findByIdAndUpdate(req.params.id, req.body)
.then((project) => {
if (!project)
res.status(400).json({message: MESSAGE.PROJECT_NOT_FOUND});
else
res.status(302).json({message: MESSAGE.PROJECT_UPDATED_SUCCESS});
})
Note: I need to remove the field from the collection for the particular document, I don't want to remove the field from the object.