For example i have document like this
{_id:1,
name:"John"
}
After adding new field it should be like this
{_id:1,
name:"John",
last_name:"doe"
}
CodePudding user response:
You probably want to use the updateOne
API with the $set
update operator:
db.collection.updateOne({_id: 1}, {$set: {last_name: "doe"}});
You didn't mention which library you're using, so I cannot recommend a specific call, but I'd assume that something like this should usually be available.