How do handle relations in document stores

199 Views Asked by At

I do understand that relations are not really needed in document stores, but for some things they can still be useful. Or am I wrong (snowed in on RDBMS)?

For instance:

Let's say that I got a bunch of files and their revision history:

File
   Name
   Path
   CreatedBy
   .. etc ..
   Revision
      Date
      Info 
      CreatedBy

Should I add the User object to CreatedBy for the file and all revisions, or should it be an ID referencing the User document? What's the common practice?

1

There are 1 best solutions below

0
On

Should I add the User object to CreatedBy for the file and all revisions, or should it be an ID referencing the User document? What's the common practice?

Both MongoDB and CouchDB have articles regarding this topic and I would say it depends on your scenario, data and DB system you using. If the data you consider to embedd or reference are big, you should reference it because for example CouchDB doesn't support (as far as I know) returning only part of the document in case it's large and you want to retrieve only basic/selected structure. On the other hand embedding can help you during querying since you don't have to look up for the referenced documents, but this really depends on the system you are using.