PostgreSQL over MongoDB
MongoDB has recently got popular; however, nothing beats a relational database for really developing your knowledge of databases. Once you understand relational databases, it gives you really good tools and mental models to work with MongoDB. MongoDB is very simple and you can think of it as a JSON data structure where we just have JSON that looks like an object and we store that information there. With SQL and relational databases it is more complex than that. Understanding this means you are miles ahead when it comes to understanding databases.
In order to get PostgreSQL set up on our computer we need to download something called GUI or graphical user interface for PostgresSQL. This exists for pretty much any database out there. In our case we use PSequel (It’s free!!!). Once you have PSequel installed you’ll have it in your application folder and you can follow along.
We use Brew on Mac to have PostgreSQL installed, but every time you do something with homebrew, you always want to make sure that you do a brew update to have everything up to date.
By running ‘brew install postgresql’ you can set up PostgreSQL to your laptop. Then in order to start PostgreSQL you need to run ‘brew services start postgresql’ in your terminal. Any database that you download you are essentially downloading the software and then you want to start the service. Simple command of ‘brew services stop postgresql’ will stop PostgreSQL service.
Now in order to use PostgresSQL we need to create a database. The way we do it is to use the ‘createdb’ command that has come once we have installed PostgreSQL. The name for the database is up to you.
If at this stage you go back to PSequel, you can see the host which is the link to where the database is located and the port number, which is by default 5432. By clicking connect button you get connected to the database. The other way to connect is to use psql ‘name’ command from the terminal. Now we are inside of PostgreSQL that is running on our computer and we can create tables, joins with SQL commands.
PostgreSQL is the world’s most advanced open source object-relational database system with a strong reputation for reliability, feature robustness, and performance. The graph above shows the transaction performance comparison for both databases and PostgreSQL is the obvious winner for a faster performance and lower latency.