I have many mongoDb documents like so
{
store:"Jacks Pizza",
storeNumbers:[
{
"chef":"Giovanni",
"number":"7203305544"
}
]
},
store:"Felicias Kitchen",
storeNumbers:[
{
"chef":"Gina",
"number":"+19161214594"
}
]
I would like to append a "+1" prefix to all such numbers that don't have a +1 country code attached to them.
Here's what I have tried-
db.users.updateMany({
"storeNumbers.number" : {
$exists: true,
$ne:"",
$regex: /^(?!\+)^(?![a-zA-Z])/
}
},
[ {
$set : {
"storeNumbers.$.number" : {
"$concat": [ "+1" , "$storeNumbers.$.number"]
}
}
}
]
);
This gives me an error saying that I cannot perform concat on elements in an array.
How would you do this?