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 - #

Sign in with OpenID

Auto-HTML: Line breaks are preserved; URLs will be converted in to links.

Manual XHTML: Enter your own, valid XHTML. Allowed tags are a, p, blockquote, ul, ol, li, dl, dt, dd, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, sub, sup, br, pre

A django site