Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Using Mongo for Real-Time Analytics. MongoDB supports an “upsert” query, which when combined with the $inc operator can cause counter fields to be incremented if they exist and created otherwise. This makes it a great fit for real-time analytics applications (one increment per page view), something that regular relational databases aren’t particularly good at.

Tagged , , , ,

2 comments

  1. For the record, something like "INSERT INTO Table (id, views) VALUES (1234, 1) ON DUPLICATE KEY UPDATE views = views + 1;" works pretty well for this purpose in MySQL.

    Paul Hammond - 1st July 2009 04:36 - #

  2. Just to chime in on Paul's point. It's a little strange to be issuing insert statements when *most* of the time you think it'll be an update. but ON DUPLICATE KEY UPDATE is a really really neat feature. Works on any unique index, not just primary keys.

    Koz - 1st July 2009 10:30 - #

Comments are closed.
A django site