Dwight's blog
Why MongoDB is (somewhat) feature-heavy

MongoDB (which I work on) is at the feature-rich end of the spectrum of NoSQL products.  Not compared to Oracle, but compared to say, Amazon Dynamo.

This was intentional. The goal was to create something general purpose that can be used, with ease, to handle a reasonably broad swath of use cases. And sometimes you need features to do that.  Secondary indexes, sorting, unique key constraints, things like that…things traditional databases have.  That is to say, the goal with the project wasn’t to make something scalable that handles a particular use case, but something scalable that works with a reasonably broad set of use cases.  That philosophy has driven a lot of what the product has ended up to be.

For example, support we are writing a content management system and we are going to store documents and allow voting on the documents.  No one should be allowed to vote more than once. In the example below we remember who has voted in an array. What we are doing is “for document 700, increment votes by 1 and add joe to the voters list; if joe has already voted do nothing.”  Note that the statement executes atomically — there is no way that joe could vote twice.

db.docs.update( { _id: 700, voters : { $ne : ‘joe’ } },
                { $inc : { votes : 1 },
                  $push : { voters : ‘joe’} }
              )

A small point but I like the example. And for me personally I find it clean enough I would be tempted to use mongo for the system even if I only needed one server.

btw the example above is in mongo shell syntax but can be done the same way from any programming language.

  1. cliveboulton reblogged this from dmerr
  2. dmerr posted this
blog comments powered by Disqus

Quantcast