I need to update/replace the character ‘&’ within a string in the noteDesc string value (in bold below), I want to change the character from & to ‘and’. The below is part of my document.
{
“_id”: {
“$oid”: “613b605c62c5e40010c70dc4”
},
“section”: [{
“section_idx”: {
“$numberLong”: “0”
},
“premiumDetails”: {
“overrideOption”: “N/A”,
},
“systemNotes”: {
“note”: [{
"noteDesc": “FVEE at night exclusion added to Buildings & Contents cover.”,
“noteTypeKey”: 69,
“noteStatusKey”: 3
}
I have tried using the below script to make the update/replacement, but I haven’t been able to make it work. Any help anyone can give me would be greatly appreciated.
db.quoteSection.updateMany([ {
$project: { noteDesc: {$replaceOne: { input: "$noteDesc", find: "&", replacement: "and"}} } }
])
The other method I tried is:
db.quoteSection.findOneAndUpdate(
{
$and:
{“section.0.systemNotes.note.0.noteDesc”:{$regex: ‘&’}}
},
{
$set:{
“section.0.systemNotes.note.0.noteDesc”: “and”
}
},
{
arrayFilters : [
{
“section.0.systemNotes.note.0…noteTypeKey”: 69
}
]
}
);