title: MongoDB: Designing a statistics dashboard schema
body: <p>I'm designing a database for statistics dashboard, the data is going to be aggregated from my main system and saved in Mongo.</p>
  
  <p>I'm trying to find the best way to model my Database, the issue i'm having is that users can filter the graphs based on different criteria like (Time Range, Age group, Gender)</p>
  
  <p>This article is very helpful regarding Time range but i'm confused how to mix all the filters together. </p>
  
  <p><a href="http://blog.mongodb.org/post/65517193370/schema-design-for-time-series-data-in-mongodb" rel="nofollow">http://blog.mongodb.org/post/65517193370/schema-design-for-time-series-data-in-mongodb</a> </p>
  
  <p><strong>For example</strong></p>
  
  <p>Generate <code>Total page views per product</code> graph, the mongo db record should look similar to:</p>
  
  <pre><code>{
    timestamp_hour: ISODate("2013-10-10T23:00:00.000Z"),
    type: “page_views”,
    product_id: 1550
    values: {
      0: { 0: 999999, 1: 999999, …, 59: 1000000 },
      1: { 0: 2000000, 1: 2000000, …, 59: 1000000 },
      …,
      58: { 0: 1600000, 1: 1200000, …, 59: 1100000 },
      59: { 0: 1300000, 1: 1400000, …, 59: 1500000 }
    }
  }
  </code></pre>
  
  <p>This would work really well if users can only filter Time Range, but then how to organize this if users mix it with Age group or gender</p>
  
  <pre><code>{
      timestamp_hour: ISODate("2013-10-10T23:00:00.000Z"),
      type: “page_views”,
      product_id: 1550
      values: {
          0: { 
              0: {
                  total: 999999,
                  age_group: {
                      teenagers: 4032932,
                      adults: 432942,
                      ...
                  },
                  gender: {
                      male: 4239423,
                      female: 4342343
                  }
  
              },
              1: {
                  total: 999999,
                  age_group: {
                      teenagers: 4032932,
                      adults: 432942,
                      ...
                  },
                  gender: {
                      male: 4239423,
                      female: 4342343
                  }
              },
              ....
              59: {
                  total: 999999,
                  age_group: {
                      teenagers: 4032932,
                      adults: 432942,
                      ...
                  },
                  gender: {
                      male: 4239423,
                      female: 4342343
                  }
              }
          },
          ....
          59: { 
              0: {
                  total: 999999,
                  age_group: {
                      teenagers: 4032932,
                      adults: 432942,
                      ...
                  },
                  gender: {
                      male: 4239423,
                      female: 4342343
                  }
  
              },
              1: {
                  total: 999999,
                  age_group: {
                      teenagers: 4032932,
                      adults: 432942,
                      ...
                  },
                  gender: {
                      male: 4239423,
                      female: 4342343
                  }
              },
              ....
              59: {
                  total: 999999,
                  age_group: {
                      teenagers: 4032932,
                      adults: 432942,
                      ...
                  },
                  gender: {
                      male: 4239423,
                      female: 4342343
                  }
              }
          },
      }
  }
  </code></pre>
  
  <p>The issue i can see with this, is what if users mix (Age range, Age group and gender) together</p>