Mongoose overwrite the document rather that `$set` fields

Viewed 20327

Say, i have a document:

{
  _id: 'some_mongodb_id',
  name: 'john doe',
  phone: '+12345678901',
}

I want to update this document:

.findOneAndUpdate({_id: 'some_mongodb_id'}, {name: 'Dan smith'})

And the result should be this:

{
  _id: 'some_mongodb_id',
  name: 'Dan smith',
}

The property, that is not specified, should be removed.

How do i do that?

2 Answers
Related