couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Samuel Williams <>
Subject Data modelling
Date Thu, 12 Jul 2012 09:03:50 GMT

I need to model some relationships.

(1) With a one-to-many relationship, should I keep the keys of the many
objects in the one, or for each many object have the key of the one, or


{"_id": "bank-account-1", ..., transactions: ["transaction-key-1",
"transaction-key-2", "transaction-key-3"]}
{"_id": "transaction-key-1", ...}
{"_id": "transaction-key-2", ...}
{"_id": "transaction-key-3", ...}


{"_id": "bank-account-1", ...}
{"_id": "transaction-key-1", ..., "bank-account": "bank-account-1"}
{"_id": "transaction-key-2", ..., "bank-account": "bank-account-1"}
{"_id": "transaction-key-3", ..., "bank-account": "bank-account-1"}

Both are a possibility. However, with the first approach, the document may
get very large. This leads into my next question:

(2) W.r.t. denormalizing data - sometimes it naturally makes sense, e.g.
invoice with multiple line items stored in an array vs invoice with
multiple line item documents.

With an invoice, once you make the invoice it doesn't usually change that
much and you also want the data together when you access it, e.g. to
display, however with a bank account the transactions are changing
frequently (e.g. new transactions every day).

I was wondering if I should consider batching together transactions, e.g. a
document for each month's worth of transactions, or perhaps one per year,
etc. That way when modifying transactions, you don't need to specify the
entire huge document with 1000s of individual items.

I would appreciate any feedback and suggestions/advice.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message