I have a collection in MongoDB.(Technically it is the cosmosDB API for MongoDB but in theory that shouldn’t matter.) The collection contains nested arrays of strings. These strings contain brackets inside them, and I need to remove them from the strings inside the arrays. Sample (fake) data:
{
“Thing_id”: “100”,
“Thing_name”: “Thing100”
“Comments”: [
“Good: [Thing100 is awesome]”,
“Bad: [I will never buy Thing100 again.]”
]
},
{
“Thing_id”: “101”,
“Thing_name”: “Thing101”
“Comments”: [
“Comparative: [Thing101 is so much better than Thing100.]”,
“Bad: [Who designed such piece of …]”
]
}
]
Any above syntax errors are because I am typing it on my phone…my apologies if it is not well-formed json/bson. To recap, I want to remove just the brackets in each value in the comments arrays. I am using pymongo to connect to the DB, and also python 3.7.4.
I have searched for how to do this, but all I can find are how to update the whole value in the array instead of replacing a character in the string inside the array.
FindAndModify() looked promising until I found out it will only do the first document found.
Is the only option to query the collection and loop through each document?