Tuesday 1 November 2016

MongoDB Tutorial

MongoDB tutorial provides basic and advanced concepts of SQL. Our MongoDB tutorial is designed for beginners and professionals.
MongoDB is a No SQL database. It is an open-source, cross-platform, document-oriented database written in C++.
Our MongoDB tutorial includes all topics of MongoDB database such as insert documents, update documents, delete documents, query documents, projection, sort() and limit() methods, create collection, drop collection etc. There are also given MongoDB interview questions to help you better understand the MongoDB database.

Prerequisite

Before learning MongoDB, you must have the basic knowledge of SQL and OOPs.

Audience

Our MongoDB tutorial is designed to help beginners and professionals.

Problem

We assure that you will not find any problem in this MongoDB tutorial. But if there is any mistake, please post the problem in contact form.

What is MongoDB

MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling.
In simple words you can say that - Mongo DB is a document oriented database. It is an open source product, developed and supported by a company named 10gen.
MongoDB is available under General Public license for free and it is also available under Commercial license from the manufacture.
The manufacturing company 10 gen has given the definition of Mongo DB:
"Mongo DB is scalable, open source, high performance, document oriented database." - 10 gen
MongoDB was designed to work with commodity servers. Now it is used by company of all sizes, across all industry.

Purpose to build MongoDB

This may be a very genuine question that - "what was the need of MongoDB although there were many databases in action?"
This is a very simple answer:
All the modern applications require big data, fast features development, flexible deployment and the older database systems not enough competent, so the MongoDB was obviously needed.
Main purpose to build MongoDB:
  • Scalability
  • Performance
  • High Availability
  • Scaling from single server deployments to large, complex multi-site architectures.

Key points of MongoDB

  • Develop Faster
  • Deploy Easier
  • Scale Bigger

    History of MongoDB

    The initial development of MongoDB began in 2007 when the company was building a platform as a service similar to window azure.
    "Window azure is a cloud computing platform and infrastructure, created by Microsoft, to build, deploy and manage applications and service through a global network."
    MongoDB was developed by a NewYork based organization named 10gen which is now known as MongoDB Inc. It was initially developed as a PAAS (Platform As A Service). Later in 2009, it is introduced in the market as an open source database server that was maintained and supported by MongoDB Inc.
    The first ready production of MongoDB has been considered from version 1.4 which was released in March 2010.
    MongoDB2.4.9 was the latest and stable version which was released on January 10, 2014.
    First of all, we should know what is document oriented database?

    Example of document oriented database

    MongoDB is a document oriented database. It is a key feature of MongoDB. It offers a document oriented storage. It is very simple you can program it easily.
    MongoDB stores data as documents, so it is known as document oriented database.
    1. FirstName = "Ajeet",                                                                                                           
    2. Address = "Laxmi Nagar",                                                                                                   
    3. Spouse = [{Name"Chaaru"}].                                                                                           
    4. FirstName ="Ravi",  
    5. Address = "Loni"  
    There are two different documents (separated by ".").
    Storing data in this manner is called as document oriented database.
    Mongo DB falls into a class of databases that calls Document Oriented Databases. There is also a broad category of database known as No SQL Databases.

    Features of MongoDB

    These are some important features of MongoDB:
    1. Support ad hoc queries
    In MongoDB, you can search by field, range query and it also supports regular expression searches.
    2. Indexing
    You can index any field in a document.
    3. Replication
    MongoDB supports Master Slave replication.
    A master can perform Reads and Writes and a Slave copies data from the master and can only be used for reads or back up (not writes)
    4. Duplication of data
    MongoDB can run over multiple servers. The data is duplicated to keep the system up and also keep its running condition in case of hardware failure.
    5. Load balancing
    It has an automatic load balancing configuration because of data placed in shards.
    6. Supports map reduce and aggregation tools.
    7. Uses JavaScript instead of Procedures.
    8. It is a schema-less database written in C++.
    9. Provides high performance.
    10. Stores files of any size easily without complicating your stack.
    11. Easy to administer in the case of failures.
    12. It also supports:
    • JSON data model with dynamic schemas
    • Auto-sharding for horizontal scalability
    • Built in replication for high availability
    Now a day many companies using MongoDB to create new types of applications, improve performance and availability.
  • NoSQL Databases

    We know that MongoDB is a NoSQL Database, so it is very necessary to know about NoSQL Database to understand MongoDB throughly .

    What is NoSQL Database

    Databases can be divided in 3 types:
    1. RDBMS (Relational Database Management System)
    2. OLAP (Online Analytical Processing)
    3. NoSQL (recently developed database)

    NoSQL Database

    NoSQL Database is used to refer a non-SQL or non relational database.
    It provides a mechanism for storage and retrieval of data other than tabular relations model used in relational databases. NoSQL database doesn?t use tables for storing data. It is generally used to store big data and real-time web applications.

    History behind the creation of NoSQL Databases

    In the early 1970, Flat File Systems are used. Data were stored in flat files and the biggest problems with flat files are each company implement their own flat files and there are no standards. It is very difficult to store data in the files, retrieve data from files because there is no standard way to store data.
    Then the relational database was created by E.F. Codd and these databases answered the question of having no standard way to store data. But later relational database also get a problem that it could not handle big data, due to this problem there was a need of database which can handle every types of problems then NoSQL database was developed.

    Advantages of NoSQL

    • It supports query language.
    • It provides fast performance.
    • It provides horizontal scalability.

      MongoDB advantages over RDBMS

      In recent days, MongoDB is a new and popularly used database. It is a document based, non relational database provider.
      Although it is 100 times faster than the traditional database but it is early to say that it will broadly replace the traditional RDBMS. But it may be very useful in term to gain performance and scalability.
      A Relational database has a typical schema design that shows number of tables and the relationship between these tables, while in MongoDB there is no concept of relationship.

      MongoDB Advantages

      • MongoDB is schema less. It is a document database in which one collection holds different documents.
      • There may be difference between number of fields, content and size of the document from one to other.
      • Structure of a single object is clear in MongoDB.
      • There are no complex joins in MongoDB.
      • MongoDB provides the facility of deep query because it supports a powerful dynamic query on documents.
      • It is very easy to scale.
      • It uses internal memory for storing working sets and this is the reason of its fast access.

      Distinctive features of MongoDB

      • Easy to use
      • Light Weight
      • Extremely faster than RDBMS

      Where MongoDB should be used

      • Big and complex data
      • Mobile and social infrastructure
      • Content management and delivery
      • User data management
      • Data hub

      Performance analysis of MongoDB and RDBMS

      • In relational database (RDBMS) tables are using as storing elements, while in MongoDB collection is used.
      • In the RDBMS, we have multiple schema and in each schema we create tables to store data while, MongoDB is a document oriented database in which data is written in BSON format which is a JSON like format.
      • MongoDB is almost 100 times faster than traditional database systems.

        MongoDB Datatypes

        Following is a list of usable data types in MongoDB.
        Data TypesDescription
        StringString is the most commonly used datatype. It is used to store data. A string must be UTF 8 valid in mongodb.
        IntegerInteger is used to store the numeric value. It can be 32 bit or 64 bit depending on the server you are using.
        BooleanThis datatype is used to store boolean values. It just shows YES/NO values.
        DoubleDouble datatype stores floating point values.
        Min/Max KeysThis datatype compare a value against the lowest and highest bson elements.
        ArraysThis datatype is used to store a list or multiple values into a single key.
        ObjectObject datatype is used for embedded documents.
        NullIt is used to store null values.
        SymbolIt is generally used for languages that use a specific type.
        DateThis datatype stores the current date or time in unix time format. It makes you possible to specify your own date time by creating object of date and pass the value of date, month, year into it.

No comments:

Post a Comment