There are a lot of "why not JOIN?" questions here, to understand who to use mongodb... But even the guide at model-embedded-one-to-many-relationships-between-documents not show the basic clues...
There are to approaches:
generate an array that contains the "embedded data" of the join, to produce "on fly" data. (using
find()and what more simple algoritm?)use the db.collection.insert to produce "persistent data".
So, if I am at mongo terminal, what the simplest way to do that?
real-life dataset example
At https://github.com/datasets/country-codes we have
country-codes.csv: a table with ~250 rows.
datapackage.json: a complex structure with the country-codes table metadata, at
resources.schema.fields.
So, before to do queries at mongo in the terminal, we can perform something like
wget -c https://raw.githubusercontent.com/datasets/country-codes/master/data/country-codes.csv
wget -c https://raw.githubusercontent.com/datasets/country-codes/master/datapackage.json
mongoimport -d ccodes_db -c ccodes --type csv --file country-codes.csv --headerline
mongoimport -d ccodes_db -c ccodes_meta datapackage.json --jsonArray
mongo
show dbs
use ccodes_db
So, lets "join" ccodes_meta with ccodes collections at mongo... The task is to embed fields name and description (of ccodes_meta) into the ccodes collection... With the simplest algorithms (not need best performance), see itens 1 and 2 of the question.