MongoDB: Welcome to the NoSQL

Logo_gpsToday we want to talk about MongoDB.

MongoDB is a NoSQL database that each time has more users and support from the developers. We spend to summarize some of its features as well as some impressions of our experience with MongoDB.

1. It Is NoSQL

A NoSQL database is a DB that does not use SQL statements, nor does it have the typical structure of relational databases such as SQL Server or Oracle. In the case of MongoDB, it is document-oriented, which would be the equivalent of a row in a table (Collection in MongoDB) in a relational database.

2. Non-Relational

Either it doesn’t use relationships, which implies some advantages anddisadvantages. Let’s see an example:

If you have a web page, from which only the contents of the pages are read and there are no relationships, MongoDB would probably be a highly recommended option. On the other hand, for a more complex application in which you have to ensure the referential integrity, you should opt for a relational database.

Another advantage that this structure has is that we saves a lot of space and fields to null: if we have a table in a relational database and a new field is added to that table, to all the records that were already created, a field is added to null to each one. With a structure of documents like MongoDB, this does not happen, because it adds only that field to the documents that have it. We in a collection (table) could have the following documents:

[{"_ id": 1, "name": "John","Address": { "street": "San Jose", "number": 12 } }, 
{"_ id": 2, "name": "Alberto", "surname": "López", "Telefono": "123456789"}]

By not having a fixed structure, it allows us to save a lot of space in the database, and to have useless fields. It also allowsus to save a lot of relationships, because in a single table we would have the details of the address for example. If we had a mobile accessories store, we could have in the same table the models with which they are compatible an article, avoiding thus a complex consultation join, the collection would have a structure similar to:

{"_ id": 5, "item": "Holster", "Manufacturer": "Samsung","models":[ "S5", "S6", "S7" ]}

Despite not being a relational database, it is still a database, so we can create indexes, make queries type select, inserts, etc.

3. Why try it?

First of all, it has drivers for different programming languages, Java, PHP, NodeJS… On the official website you will have more details. This gives us a lot of play when it comes to implementing it, because we could use it in any type of application and in the language that you are most comfortable.

If you are used to dealing with relational databases you should not have problems with MongoDB. For example, to find the document with ID 27 of the students collection would be:

db. Students. FIND ({ID: 27})

And finally, the last reason would be the great support it has, there is a lot of documentation, free online courses provided by the manufacturer itself and its already proven guarantee in terms of scalability and high availability.

I hope this post has served you, see you in upcoming entries MongoDB.


Database team