I have this document in my mongo-db
{
"key": 1,
"name" "abc"
}
now I want to update it and want to set age as 20 so I used update query by keeping upsert as true but its not updating as age field don’t exist , how can I make query so it create the field if it doses not exist
2
Answers
doccumentation
You can try using the findOneAndUpdate function
Refer to https://sparkbyexamples.com/mongodb/mongodb-insert-if-not-exists/?amp=1