Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages of using a schema-free database like MongoDB compared to a relational database?

I'm used to using relational databases like MySQL or PostgreSQL, and combined with MVC frameworks such as Symfony, RoR or Django, and I think it works great.

But lately I've heard a lot about MongoDB which is a non-relational database, or, to quote the official definition,

a scalable, high-performance, open source, schema-free, document-oriented database.

I'm really interested in being on edge and want to be aware of all the options I'll have for a next project and choose the best technologies out there.

In which cases using MongoDB (or similar databases) is better than using a "classic" relational databases? And what are the advantages of MongoDB vs MySQL in general? Or at least, why is it so different?

If you have pointers to documentation and/or examples, it would be of great help too.

like image 283
Guillaume Flandre Avatar asked Jan 22 '10 13:01

Guillaume Flandre


People also ask

What is one advantage of non-relational NoSQL databases compared to relational databases?

When compared to relational databases, NoSQL databases are often more scalable and provide superior performance. In addition, the flexibility and ease of use of their data models can speed development in comparison to the relational model, especially in the cloud computing environment.

What are the major differences between MongoDB and relational databases?

Fundamental Differences The immediate and fundamental difference between MongoDB and an RDBMS is the underlying data model. A relational database structures data into tables and rows, while MongoDB structures data into collections of JSON documents. JSON is a self-describing, human readable data format.

What type of situation using MongoDB is better than relational databases?

MongoDB is almost 100 times faster than traditional database system like RDBMS which is slower in comparison with the NoSQL databases. There is no support for complex joins in MongoDB but RDBMS supports complex joins which can be difficult to understand and take too much time to execute.

What are the most important advantages of using non-relational databases?

The obvious advantage of a non-relational database is the ability to store and process large amounts of unstructured data. As a result, it can process ANY type of data without needing to modify the architecture. So, creating and maintaining a NoSQL database is faster and cheaper.


2 Answers

Here are some of the advantages of MongoDB for building web applications:

  1. A document-based data model. The basic unit of storage is analogous to JSON, Python dictionaries, Ruby hashes, etc. This is a rich data structure capable of holding arrays and other documents. This means you can often represent in a single entity a construct that would require several tables to properly represent in a relational db. This is especially useful if your data is immutable.
  2. Deep query-ability. MongoDB supports dynamic queries on documents using a document-based query language that's nearly as powerful as SQL.
  3. No schema migrations. Since MongoDB is schema-free, your code defines your schema.
  4. A clear path to horizontal scalability.

You'll need to read more about it and play with it to get a better idea. Here's an online demo:

http://try.mongodb.org/

like image 148
Kyle Banker Avatar answered Sep 19 '22 09:09

Kyle Banker


There are numerous advantages.

For instance your database schema will be more scalable, you won't have to worry about migrations, the code will be more pleasant to write... For instance here's one of my model's code :

class Setting   include MongoMapper::Document    key :news_search, String, :required => true   key :is_availaible_for_iphone, :required => true, :default => false    belongs_to :movie end 

Adding a key is just adding a line of code !

There are also other advantages that will appear in the long run, like a better scallability and speed.

... But keep in mind that a non-relational database is not better than a relational one. If your database has a lot of relations and normalization, it might make little sense to use something like MongoDB. It's all about finding the right tool for the job.

For more things to read I'd recommend taking a look at "Why I think Mongo is to Databases what Rails was to Frameworks" or this post on the mongodb website. To get excited and if you speak french, take a look at this article explaining how to set up MongoDB from scratch.

Edit: I almost forgot to tell you about this railscast by Ryan. It's very interesting and makes you want to start right away!

like image 32
marcgg Avatar answered Sep 21 '22 09:09

marcgg