Introduction to MongoDB




MongoDB is a powerful, flexible, and scalable general-purpose database. It is an agile database that allows schemas to change quickly as applications evolve. It is a NoSQL database. It is a powerful, flexible and scalable general-purpose database.
It is a document-oriented database replaces the concept of a "row" with a more flexible model, the "document". Instead of using rows and tables, MongoDB uses collections and documents.

History

MongoDB is the most popular NoSQL database system. It is a document oriented database written in C++ by Dwight Merriman and Eliot Horowitz. It is not a relational database and is developed and supported by a company 10gen. It was created by company 10gen in 2007 and it was production ready in 2010 with version 1.4. Its recent stable version 2.4 was released in 2013. MongoDB stores the data in BSON format, which provides a binary representation of JSON-like documents in JavaScript.


A database in MongoDB can have a set of collections. MongoDB stores documents within collections and collection can hold a set of documents. Document is an ordered set of keys with associated values. A document is basic unit of data in MongoDB and is roughly equivalent to a row in relational database management system. Documents have dynamic schema. This means that documents in the same collection do not need to have the same set of fields or structure and they can have any number of different “shapes” As there are no predefined schemas, so a document’s keys and values are not of fixed types or sizes. Schema-less database makes the adding and removing fields easier, as in MongoDB we do not need to define the columns and this makes the development faster.


Why MongoDB?

MongoDB is used to handle big data. When the concept of flat files system came into existence, at that time all the companies had their own implementation of flat files and lot of efforts and energy was used in programming that how to retrieve data from files, how to write data to the files, as there was no standard format of storing data into files.


Then in 1970’s Relational database was created and then there was a standard format of storing and querying data. In Relational database we just write queries to add, update and retrieve data. It handles the data until the data becomes too big. As the data which is used today is mostly unstructured data and relational databases are not capable of handling unstructured or semi-structured data, which is in the form of numeric data, emails, videos, audio etc.
It became difficult for relational database management system to handle this amount of data and to overcome this problem thus, NoSQL (not only SQL) database came into existence.

NoSql is a non-relational database which provides a mechanism for storage and retrieval of data in a modeled form rather than a tabular form, as it provides schema-less structures of database. Also NoSql provides horizontal scalability, means we can scale by adding more machines into pool of resources and is based on partitioning of data.






Different categories of database in NoSQL



   1. Document Store Database: 
    It is the database in which data is stored in documents instead of rows and columns. It is simply stored in JavaScript like JSON JavaScript Object Notation and the language of database that is used internally is JavaScript. Document store database could be a nested document or a key-value pairs. Since JavaScript is very popular in the web market and most of the developers are familiar with it, thus these kinds of NoSQL database are very popular with web developers and also these are same as Key-Value Stores are Scheme free.

      
      Database comes under document store database:


   2. Graph Store Database: 

    This kind of database is designed for data whose relations are well represented as a graph. The kind of data could be social relations, public transport links, road maps or network typologies.

            Databases that comes under graph store database



3.Key-value Store Database: 
The key value type basically, uses a hash table in which there exists   unique key and a pointer to a particular item of data. In this model, data is represented as a collection of key-value pairs, such that each possible key appears at most once in the collection. Key valued stores are those types of NoSQL database that are schema free. That means you will be having a field “Name” and in the second document of the same collection it’s not necessary to pass the same field “Name” again. This is the most common kinds of NoSQL databases that are currently in the market.

          Database that come under Key-Values database:

     
    4.  Wide-column stores Database:
In Wide-column stores database, data is stored in cells grouped in columns of data rather than as rows of data. Columns are logically grouped into column families. Read and write is done using columns rather than rows. Most relational DBMS, store data in rows but the benefit of storing data in columns is, fast access and data aggregation.


           Databases that comes under wide-column database:



How NoSQL is different from MySQL


   1.  Data Representation

MySQL represents data in the form of tables and rows. NoSql database represents data as collections of JSON documents.

   2.  Relationships

MySQL support join of tables, while NoSql database use embedding and linking of documents. In embedding one document is placed inside another document.

   3.  Schema Designs

MySQL requires you to define the columns before you can store anything and every row in a table must have the same columns, while in NoSql database you do not need to define any schema. You can just create the collection which can simply have different fields.

   4.  Scalability

       MySQL databases are vertically scalable. You can manage              increasing load by increasing the CPU, RAM, etc on a single            server. On the other hand, NoSql database are horizontally                scalable. You can just add few more servers easily into your            database infrastructure to handle the large traffic.

   5.  Properties

       MySQL databases emphasizes on ACID properties (Atomicity,        Consistency, Isolation and Durability) whereas the NoSQ                database follows the Brewers CAP theorem (Consistency,                Availability and Partition tolerance).




MongoDB is a NoSQL database used to handle the Big Data, which overcomes the problems of relational databases with some extra features like: schema-less structure, indexing, load balancing, capped collections, aggregation, and replication of data.




Previous
Next Post »

Popular Posts