NoSQL has been getting a lot of attention in our industry recently. I'm really interested in what peoples thoughts are on the best use-cases for its use over relational database storage. What should trigger a developer into thinking that particular datasets are more suited to a NoSQL solution. I'm particularly interested in MongoDB and CouchDB as they seem to be getting the most coverage with regard to PHP development and that is my focus.


Just promise yourself that you will never try to map a relational data model to a NoSQL database like MongoDB or CouchDB... This is the most common mistake developers make when evaluating emerging tech.

That approach is analogous to taking a car and trying to use it to pull your cart down the road like a horse.

It's a natural reaction due to everyone's experience of course, but the real value in using a document database is being able to simplify your datamodel and minimize your suffering as a developer. Your codebase will shrink, your bugs will be fewer and easier to find, performance is going to be awesome, and scale will be much simpler.

As a Joomla founder I'm biased :-) but coming from the CMS space, something like MongoDB is a silver bullet as content maps very naturally to document systems.

Another great case for MongoDB is real-time analytics, as MongoDB has very strong performance and scale particularly regarding concurrency. There are case studies at the MongoDB.org website that demonstrate those attributes.

I agree with the notion that each database has its own aims and use cases; take the purpose of each database for evaluation accordingly.


Some great use-cases - for MongoDB anyway - are mentioned on the MongoDB site. The examples given are real-time analytics, Logging and Full Text search. These articles are all well worth a read http://www.mongodb.com/use-cases

There's also a great write-up on which NoSQL database is best suited to which type of project: http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis


I'd suggest this article by Rick Cattell about miscellaneous data stores (a.k.a. NoSQL), their differences and some of their use-cases: http://www.cattell.net/datastores/index.html


What I like about NoSQL has nothing to do with performance and everything to do with usability. Document stores are just easier to work with when your atomic data units are document-like, because it's trivial to serialize to and from objects. It's just more fun, and that's an important factor for personal or side projects.


I have been using NoSQL DBs for a while now, and this is my contribute to the topic:

A great use case for a NoSQL database is an application for statistics and / or reports generation, expecially when data is provided from a third party source.

In a situation like that a NoSQL database can be a great choice

Let's consider, for example, MongoDB:

Once you have your data in JSON, ( it could come from a third party API, or be exported from an sql-application) in MongoDB is pretty strightforward to import and update the JSON data in the database; for example using the command-line mongoimport utility

At this point is very simple to build dynamic queries with filtering and grouping, that well fit with this kind of application.

For example, using the Aggregation Framework:

$pipeline = [];

//filter by date
$pipeline[] = [ '$match' => [ 'created_at' => [ '$gte' => $starDate, '$lte' => $endDate ]  ]  ];

//if we want to filter by a specific field, we add the filter to the pipeline array
if( $filters->isFilterByField() )
    $pipeline[] = [ '$match' => [ 'field' => $fieldValue ] ];    

//group the results by date and get the count
$pipeline[] = [ '$group' => [ '_id' => '$created_at', 'num_elements' => [ '$sum' => 1 ] ] ];

return $collection->aggretate( $pipeline );

I'd like to point up the easiness with which we can dinamically add/remove filters using php data structures and avoiding tedious string concatenation to build up our queries. With this approach adding/removing filters dinamycally is as easy as adding / removing elements from an array

Another great benefit comes from the fact that a solution like this is likely to be faster than using a relational database, where we have to make joins with different tables to get all the data we need

Besides, this use case is optimal because avoids all the principal limits of a NoSQL database:

  • Lack of transactions: The application doesn't perform writes but only reads, so we don't need transactions at all

  • Lack of joins between tables: We don't need joins, as we can use redundancy to store our denormalized data in the collections. As we only read data, we don't need to be worried about synchronizing denormalized data among updates.

This way we can focus on storing the data with redundancy in a manner that well fits to our queries, that will be focus on single collections.

I'm just writing this because had i read something like that some times ago, it would have been saved me some time to make researches

Hope it will be useful to someone