Mongodb Get Started

by Didin J., updated on Jul 28, 2017 Mongodb Get Started

Why use MongoDB for web application? This is real in my experience that MongoDB faster and cheaper than Relational Database.


MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. A record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents. 

The advantages of using documents are:

  • Documents (i.e. objects) correspond to native data types in many programming languages. 
  • Embedded documents and arrays reduce need for expensive joins.
  • Dynamic schema supports fluent polymorphism.


High Performance

MongoDB provides high performance data persistence. In particular,

  • Support for embedded data models reduces I/O activity on database system.
  • Indexes support faster queries and can include keys from embedded documents and arrays.

Yes, it is faster than RDBMS database. With same hardware spesification, MongoDB can operate faster than RDBMS database. I prove my selft after longtime ago using PostgeSQL, MS SQL and MySQL. Response time reduce very significant event I'm using ORM base frameworks.


Rich Query Language

I'm done a lot of queries for MongoDB database from programming language. It's all depend on algoritmh in programming language it self and customizeable. It's a litte different than using Stored Procedure or Function on RDMS that will eat a lot of hardware resources. 

MongoDB supports a rich query language to support read and write operations as well as:

  • data aggregation
  • Text search and Geospacial Queries


High Availability

MongoDB’s replication facility, called replica set, provides:

  • automatic failover and
  • data redundancy.

replica set is a group of MongoDB servers that maintain the same data set, providing redundancy and increasing data availability.


Horizontal Scalability

MongoDB provides horizontal scalability as part of its core functionality:

  • Sharding distributes data across a cluster of machines.
  • Tag aware sharding allows for directing data to specific shards, such as to take into consideration geographic distribution of the shards.


Support for Multiple Storage Engine

MongoDB supports multiple storage engines:

In addition, MongoDB provides pluggable storage engine API that allows third parties to develop storage engines for MongoDB.


Install MongoDB on Ubuntu

Install MongoDB on ubuntu is very easy using apt-get. Here's the step:

1. Import public key

sudo apt-key adv --keyserver hkp:// --recv 7F0CEB10

2. Create list for MongoDB

echo "deb trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

3. Reload local package

sudo apt-get update

4. Install MongoDB Packages

sudo apt-get install -y mongodb-org

That it, you just can run your newly installed MongoDB.


Run MongoDB

1. To manually start MongoDB server

$ sudo service mongodb start

2. Run MongoDB console

$ mongo

And now you can start populate data in your MongoDB. To stop MongoDB, simply hold alt+C or run

$sudo service mongodb stop