I have a document in MongoDB having this structure:
[{
"_id": {
"$oid": "66792ac155b1a3e359fe8626"
},
"main_project_id": {
"$oid": "65d37b3c9b23a29ac1f5dc37"
},
"project_id": 82492,
"form_details": {
"Field1": 82492,
"Field2": "XXX",
"Field3": "Inline",
....
},
"item": {
"01.01": 770232,
"01.01.01": 61400,
"01.01.02": 8882.85,
"01@03": 0,
}
}]
At the moment i’m able to create a view that find a point in the item keys and replace it with an underscore, as follows:
db.createCollection(
"costSummaryView",
{
"viewOn" : "costSummary",
"pipeline" : [{
$set: {
"item": {
$arrayToObject: {
$map: {
input: { $objectToArray: "$item" },
in: {
k: {
$replaceAll: {
input: "$$this.k",
find: ".",
replacement: "_",
}
},
v: "$$this.v"
}
}
}
}
}
}],
}
)
Now i’m finding a solution to find either a point and @ character to replace them both with an underscore, i tried this solution, but it doesn’t work:
db.createCollection(
"costSummaryView",
{
"viewOn" : "costSummary",
"pipeline" : [{
$set: {
"item": {
$arrayToObject: {
$map: {
input: { $objectToArray: "$item" },
in: {
k: {
$replaceAll: {
input: "$$this.k",
find: ".",
replacement: "_"
},
},
v: "$$this.v"
}
}
}
},
"item": {
$arrayToObject: {
$map: {
input: { $objectToArray: "$item" },
in: {
k: {
$replaceAll: {
input: "$$this.k",
find: "@",
replacement: "_"
},
},
v: "$$this.v"
}
}
}
},
}
}],
}
)
Is there a way to replace multiple characters?