Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoDB data modeling: Document embedding dilemma
    primarykey
    data
    text
    <p>Say I a have an application which receives requests with two parameters: X and Y. All I want to do is to count these requests, and I want to use MongoDB for the task.</p> <p>I can think of two methods to store that information in MongoDB:</p> <p>1. Having a document for each combination of X and Y:</p> <pre><code>{ _id : "X+Y", count : 34 } </code></pre> <p>2. Embedding Y into X, meaning that each X has a document which summarizes all of requests with that X:</p> <pre><code>{ _id : "X", total_count : 47, y: { "Y1" : 34, "Y2" : 13 } } </code></pre> <p>What are the pros and cons of each of these methods?<br> Is one method consitered best practice? Is there another legitimate method I'm missing? Is this a common dilemma?</p> <p>I've been reading MongoDB's manual <a href="http://docs.mongodb.org/manual/core/data-modeling/" rel="nofollow">data modeling</a> section and <a href="http://docs.mongodb.org/manual/faq/developers/#when-should-i-embed-documents-within-other-documents" rel="nofollow">a FAQ discussing this issue</a>, but I wasn't satisfied.</p> <p>Thanks</p> <p><strong>Update</strong></p> <p>My application is expected to handle about 50M requests a day, while each request holds a few attributes (such as X and Y), but a relatively small amount of them (4-5), and each request should be counted (either by insert or update).<br> This data will be queried every hour or so, and the queries are expected to use aggregation. These queries will usually query data from the last few days (up to a week).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload