MongoDB

MongoDB is a noSQL document-oriented database used for millions of users and companies because it has no cost and easy to use. But as is noSQL oriented database at first sight it could look complicated to understand or we could be lost with just a command window. So, how do we use it? Why is very popular? I will answer all those questions.

How do we install it?

First, we are going to head over to MongoDB’s official website and download the latest version:

https://www.mongodb.com/download-center/community

After you downloaded and installed, head on to the installation folder and open the bin folder and execute the program “mongo.exe” ( I recommend to make a shortcut for that application in the desktop to make it easier to locate it in the future)

After that we open the program, we will get a command window like this:

And there we will create our databases. To have a quick look of what we already have we can use the command help and it will display all the commands that we can use in it, for example “show dbs” it will display the databases that are created.

HOW TO USE IT?

As we can see we have different databases, so we need to select the database that we are going to work on, for that we use:

use (Name of the database)

Now that we are in our database, we can start by create collections that are like SQL tables, but we don’t have to specify the types of the data we are going to save in. For that we use the command:

db.(name of the collection).insertOne({ (dataname): (value),…})

After we inserted our collection, we can take a look how our collection look like, using:

db.(name of the collection).find(*{query} {projection})

We can also update our values with:

db.(name of the collection).updateOne({condition}, {$set:{the changes}})

We can delete documents:

db.(name of the collection).deleteOne({condition})

And we can delete the whole database

( For more command and information visit https://docs.mongodb.com/manual/reference/command/ )

WHY SHOULD I USE A NOSQL DATABASE LIKE MONGODB?

Nowadays there is a big amount of different types databases and the most common question is which one should I use? a SQL database or a noSQL like MongoDB? To answer that question let’s understand both types.

  • MongoDB is  one of the most popular noSQL database as it is a document orientated database. This document that we can create are made with Binary JSON ( JavaScript Object Notation). It a better option because of it store capacity and speed offering a great efficiency and reliability.
  • In the other hand we have SQL, a programming language that is used to manage data in relational databases which are used to store data and match them using common characteristics. Some of the most used SQL databases management systems are Microsoft SLQ Server and Oracle.

So, which one is better, well, let’s take a look at the “Pros and Cons” of each of them:

SQL databases:

Pros:

-Priviledge and password      system

-JOIN support

-Strict Schema

Cons:

-Stability concerns

-Predefined and inflexible

data model

MongoDB:

Pros:

-Document validation

-Fast to store and use the data

-Integrated storage engines

Cons:

-Struggles with complex transactions

-No support for transactions

As can see using MongoDB we can create collections or “tables” easily and  we don’t have to specify any kind of type or behaviour, so we can store data really quickly, while with a SQL database it will take time to prepare a table system to store that data and pass it through some controls or data validation, but the table system will help us to organize our data and have links or relate it between them, so we can store data safely and organized, knowing that everything is in their place.

So which one should I use? Well, depends on what do you want to do with your data and how are you going to use, do you need organised and have everything related? The best option is a SQL database. Do you need to store quickly a lot of data and make it dynamic? MongoDB is the option for that.

Is still not sure what to use? Here there are some example of companies that use these two different databases.

SQL

Twitter – Facebook – Walmart – Sony

MongoDB

Bosh – eBay – Adobe – Otto