This kind of operations in query may cause performance issues, if you really want in query then try $function, starting from MongoDB v4.4, Write JS code inside function,
$addFields
to add new field converted
you can change as per your need,
$function
pass both fields in args
- body
foo.replace(/d+/g, ''),
this will remove digits from string, you can change if you have better expression for replace
faa.split("")
this will split string using empty string
db.collection.aggregate([
{
$addFields: {
converted: {
$function: {
body: function(foo, faa) {
return {
foo: foo.replace(/d+/g, ''),
faa: faa.split("")
}
},
args: ["$foo", "$faa"],
lang: "js"
}
}
}
}
])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…