title: MongoDB Approaches for storing large amounts of metrics / analytics data
body: <p>We are planning on using MongoDB to store large amounts of analytics data such as views and clicks. I'm unsure on the best way to structure the documents within MongoDB to aid querying and reduce database size. </p>
  
  <p>We need to record actions agains a pagename, client and the type of action. Ideally we need stats which go down the the year/month/day/hour level, we don't need or care about views per second or minute. While this document structure looks ok, I'm aware 100 vistors would generate a 100 new documents.</p>
  
  <pre><code>{ 
    "_id" : ObjectId( "4dabdef81a34961506040000" ),
    "pagename" : "Hello",
    "action" : "view",
    "client" : "client-name",
    "time" : Date( "Mon Apr 18 07:49:28 2011" )
  }
  </code></pre>
  
  <p>Is there best practice way of doing this, either using <a href="http://www.mongodb.org/display/DOCS/Updating#Updating-$inc" rel="nofollow noreferrer">$inc</a> or <a href="http://www.mongodb.org/display/DOCS/Capped+Collections" rel="nofollow noreferrer">Capped Collections</a>?</p>