I am having the issue that I want to clone a huge dataset (around 500.000 documents) in a NoSQL database. Each of these documents is having an ID (usually something like a uuid/objectID). however, while copying the documents, each document gets a new ID. I am saving this in a dict/map: mapping[oldId] = newId
The ID of most of this documents might be part of other documents, in the best case as a complete string (e.g. parentDocument: "<someid>"), but sometimes it might be a substring (e.g. content: "See our other <a href='/<someid>'>Document</a>.
How can I somehow efficiently replace all those occurrences of multiple IDs in all those documents?
My Idea was to stringify the Document to JSON or EJSON and then do the replacement there, however, I would be still replacing thousands of strings.