MongoDB: Replicate data in documents vs. “join”

Posted by JavierCane on Programmers See other posts from Programmers or by JavierCane
Published on 2014-04-30T07:05:58Z Indexed on 2014/05/30 9:37 UTC
Read the original article Hit count: 225

Filed under:
|
|
|

Disclaimer: This is a question derived from this one.

What do you think about the following example of use case?

  1. I have a table containing orders.
  2. These orders has a lot of related information needed by my current queries (think about the products; the buyer information; the region, country and state of the sale point; and so on)
  3. In order to think with a de-normalized approach, I don't have to put identifiers of these related items in my main orders collection. Instead, I have to repeat all the information for each order (ie: I will repeat the buyer's name, surname, etc. for each of its orders).
  4. Assuming the previous premise, I'm committing to maintain all the data related to an order without a lot of updates (because if I modify the buyer's name, I'll have to iterate through all orders updating the ones made by the same buyer, and as MongoDB blocks at a document level on updates, I would be blocking the entire order at the update moment).
  5. I'll have to replicate all the products' related data? (ie: category, maker and optional attributes like color, size…)
  6. What if a new feature is requested and I've to make a lot of queries with the products "as the entry point of the query"? (ie: reports showing the products' sales performance grouping by region, country, or whatever)
    1. Is it fair enough to apply the $unwind operation to my orders original collection? (What about the performance?)
    2. I should have to do another collection with these queries in mind and replicate again all the products' information (and their orders)?
    3. Wouldn't be better to store a product_id in the original orders collection in order to be more tolerable to requirements change? (What about emulating JOINs?)
  7. The optimal approach would be a mixed solution with a RDBMS system like MySQL in order to retrieve the complete data?
    • I mean: store products, users, and location identifiers in the orders collection and have queries in MySQL like getAllUsersDataByIds in which I would perform a SELECT * FROM users WHERE user_id IN ( :identifiers_retrieved_from_the_mongodb_query )

© Programmers or respective owner

Related posts about sql

Related posts about nosql