I'm trying to replace all the unnecessary text in the field
For example I have this:
_id:12345678901,
name:"Company Z"
_id:12345678902,
name: "Corp Y"
_id:12345678902,
name: "Corporation X"
And I want to remove Corp, Corporation and Company in the field name, and make a new field for it, but I can't do it with regex
Target:
_id:12345678901,
name: "Company Z",
newName: "Z"
_id:12345678902,
name: "Corp Y",
newName: "Y"
_id:12345678902,
name: "Corporation X",
newName: "X"
Currently I have this:
db.customers.updateMany(
{ },
[{
$set: { newName: {
$replaceAll: { input: "$name", find: {"$regexFind": { input: "$name", regex: '/(Corp)|(Corporation)|(Company)/gi' } }, replacement: "" }
}}
}]
)
But it doesn't seems to work.
BTW im using mongod 4.4.14