0

Designing data intensive application by Martin Kleppmann says one-to-many relationship is implemented in document database using tree hierarchy. For example as given in code below user can hold multiple positions and that can be represented as list of designation held and organization. But Organization will be duplicate. So data can't be normalized as in RDBMS. The book further says many-to-one relation can't be represented in document DB as it doresn't support join. But it can't support one-to-many also contrary to its claim because if data is stored in separate entity then document DB can't represent as whole as given below in JSON representation. So if we say document database supports one-to-many relationship then it can't do so without storing duplicate information?

{
    "user_id": 251,
    "first_name": "Bill",
    "last_name": "Gates",
    "summary": "Co-chair of the Bill & Melinda Gates... Active blogger.",
    "region_id": "us:91",
    "industry_id": 131,
    "photo_url": "/p/7/000/253/05b/308dd6e.jpg",

    "positions": [
        {"job_title": "Co-chair", "organization": "Bill & Melinda Gates      Foundation"},
        {"job_title": "Co-founder, Chairman", "organization": "Microsoft"}
    ],
    "education": [
        {"school_name": "Harvard University", "start": 1973, "end": 1975},
        {"school_name": "Lakeside School, Seattle", "start": null, "end": null}
    ],
    "contact_info": {
        "blog": "http://thegatesnotes.com",
        "twitter": "http://twitter.com/BillGates"
  }
}
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
Shailesh
  • 405
  • 1
  • 5
  • 18
  • JFYI, mongodb has a form of join (the `$lookup` aggregation pipeline operator) – Sergio Tulentsev May 23 '19 at 09:41
  • To add to Sergio's comment, you may want to also review https://docs.mongodb.com/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/, as well as $lookup – Alex B. May 23 '19 at 10:10
  • Thank you Sergio and Alex. In the above code where 'organization' is stored as string not reference to organization entity will cause duplicate? Also if there is many-to-many relationship then document database is not right choice? either RDBMS ot Graph should be considered? – Shailesh May 25 '19 at 01:45

0 Answers0