I’ve been using MapReduce before to perform classical MR operation, the equivalent of GROUP BY in SQL.
I was wondering if it would be conceptually possible to perform a JOIN operation with MapReduce. Any idea how that could be implemented? Does it make sense to use MapReduce for this kind of operation?
Thanks!
MongoDB doesn’t support relational operations likes joins. Instead, you can denormalise your data by embedding the rows you’d JOIN on inside the outer document. So instead of joining Products to Sales, you could have a
productscollection with this schema:products
Then whenever you retrieve a product, you also get its sales data so there’s no need to join or lookup the info somewhere else.
Alternatively, you could split into two collections as you might with a relational database, then use an additional query to get a product’s sales, something like this:
SQL:
SELECT Sales WHERE ProductId = 123MongoDB:
db.sales.find( { productid: 123 } )products
sales