my collection has phonenumber field. i want to add 91 infront of phonenumber.
{
"_id": "6137392141bbb7723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":9000000001
},
{
"_id": "6137392141bbe30723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":9000000002
}
i want to update my collection like this.
{
"_id": "6137392141bbb7723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000001
},
{
"_id": "6137392141bbe30723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000002
}
im trying with this code but its not updating the field.
var x = await User.find({});
x.forEach(async function(d)
{
var phone = d.phonenumber;
var newPhoneNumber = 910000000000+phone;
console.log(newPhoneNumber);
//update
await User.updateMany({},{$set:{phonenumber:newPhoneNumber}},
{
new: true,
runValidators : true
});
})
im getting only one value for all documents like this:
{
"_id": "6137392141bbb7723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000001
},
{
"_id": "6137392141bbe30723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000001
},
{
"_id": "6137392141bbe30723",
"email": "[email protected]",
"lastname": "Cagle",
"firstname": "Brooke",
"phonenumber":919000000001
}
i don’t know whether this approach is correct or not.Thank you