Hi everyone,
I’m a MongoDB newbie who has put together his first Mongo DB. (Ubuntu platform, Mongo v5.0.8. I’m actually using the Docker container version of Mongo.)
I’m wondering if there’s a way to map a string to a database document and/or vice versa?
To explain in more detail: In my job, I have a piece of software that takes in a text string as input, processes the string, then generates output in the form of a JSON file. These JSON files can be quite diverse; no two are really alike. To analyze the output, I’ve put about a thousand of these JSON files into my Mongo DB instance.
Only now, I’m realizing that just looking at the JSON output is only half of that picture. For each document, I need the original text string associated with the JSON. (And sadly, that string is not included within the JSON itself.)
To be explicit: If I’m in Compass and I’m searching on a given input string, I need a way to pull up the corresponding JSON output document. Or, given a JSON document, I need to be able to lookup the original string. There is an exact 1:1 relationship between string and JSON; no two strings will be the same, and no two JSON documents will be the same, either. Every string will map to exactly one JSON, and vice versa.
When I uploaded my- JSON docs into Mongo, I used this mongoimport
command from the Ubuntu command line:
mongoimport --db "db01" --collection "table01" --file "output01.json"
mongoimport --db "db01" --collection "table01" --file "output02.json"
mongoimport --db "db01" --collection "table01" --file "output03.json"
...etc...
Very easy. But now, I can’t manually assign each input string to its corresponding JSON output document. I’m willing to delete the current database and re-enter everything again, perhaps with something like this:
mongoimport --db "db01" --collection "table01" --file "output01.json" --map "Input String 01"
mongoimport --db "db01" --collection "table01" --file "output02.json" --map "Input String 02"
mongoimport --db "db01" --collection "table01" --file "output03.json" --map "Input String 03"
...etc...
Of course, I don’t see something like that in the mongoimport
documentation. Does anyone have any suggestions? I don’t mind rebuilding the database to include mapping function. Thank you.