Answer the question
In order to leave comments, you need to log in
How to merge objects in a document on update in Mongoose?
Hi all. There is a document update task in MongoDB.
Suppose I have a document in the database that looks like this:
{
"phone": "+7********",
"profile: {
"username": "Username",
}
}
{
"profile": {
"firstname": "My name"
}
}
User.findOneAndUpdate(id, {$set: {profile: data.profile}}, {new: true}, (err, updatedUser) =>{
....
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question