MongoDB Tutorial – Introduction to MongoDB

MongoDB Tutorial

In this MongoDB tutorial we will discussing about NoSQL databases (i.e. NoSQL as name suggest a database which no SQL and relations between to others database tables, these databases just as simply document formatted and requirement only is storage to hard drive).

What is NoSQL ?

NoSQL is a non-relational database management systems, different from traditional relational database management systems in some significant ways. It is designed for distributed data stores where very large scale of data storing needs (for example Google or Facebook which collects terabits of data every day for their users). These type of data storing may not require fixed schema, avoid join operations and typically scale horizontally.

What is the important features of NoSQL DB?

Schema-free DB: A database schema is the structure of database system, described in a formal language supported by the database management system. In a relation database the schema defines the tables, the fields in each table and the relationships between fields and tables, generally it stored in a data dictionary. In NoSQL, collection is a group of documents where document represent a row and collection represent a table in a relational database. Collections are schema free which means within a single collection different types and structured of documents can be stored.
For example, both of the following documents can be stored in a single collection.
{“name” : “dinesh”} {“salary” : 50000} {“address” : “noida”}

Note that the previous documents have no common data elements at all. This flexibility means that schema free practice can be possible in NoSQL database.

Horizontally scalable : To scale horizontally means to add more nodes to a system (such as adding a new computer). In NoSQL system, data store can be much faster as it takes advantage of “scaling out” which means to add more nodes to a system and distribute the load over those nodes.

Categories of NoSQL DB?

1.Document Based DB:
Data is stored as documents.
An example format may be like – Employee Name=”Dinesh”, Employee Address=”Noida”, Spouse=[{Name:”Sweety”}], Salary=”50000″
such databases are CouchDB, Jackrabbit, MongoDB, OrientDB, SimpleDB, Terrastore etc.

2.XML Based DB:
Data is stored in XML format.
such databases are BaseX, eXist, MarkLogic Server etc.

3.Graph Based DB:
Data is stored as a collection of nodes, where nodes are analogous to objects in a programming language. Nodes are connected using edges.
such databases are AllegroGraph, DEX, Neo4j, FlockDB, Sones GraphDB etc.

MongoDB?

MongoDb is a Open Source database written in C++.
If the load increases, by adding more nodes (such as a computer), the performance can be retained.

It can be used to store data for very high performance applications (for example Foursquare is using it in production).
MongoDb stores data as documents. So it is a document oriented database.

Employee Name=”Dinesh”, Employee Address=”Noida”, Spouse=[{Name:”Sweety”}], Salary=”50000″
Notice there are two different documents (separated by “.”). Storing data in this fashion is called as document oriented database.

Features of MongoDB?

1. Since MongoDb offers a Document oriented storage, It is simple and easily programmable.
2. You can set an index on any attribute of a MongoDb record (as Employee Name=”Dinesh”, Employee Address=”Noida”, Spouse=[{Name:”Sweety”}], Salary=”50000″, with respect to which, a record can be sort quickly and ordered.
3. You can set mirror across local as well as wide area networks, which makes it easily scalable.
4. If load increases (more storage space, more processing power), it can be distributed to other nodes across computer networks. This is called as sharding.
5. MongoDb supports rich query to fetch data from the database.
6. MongoDb supports replacing an entire document (database) or some specific fields with it’s update() command.
7. MongoDb supports various programming languages like C, C# and .NET, C++, Erlang, Haskell, Java, Javascript, Perl, PHP, Python, Ruby, Scala (via Casbah).
8. It supports Server-side JavaScript execution. Which allows a developer to use a single programming language for both client and server side code.
9. MongoDb is easily installable.

MongoDB tutorial Contents-

  1. Install MongoDB on Windows
  2. MongoDB Hello World Example
  3. Create database or collection in MongoDB
  4. Java MongoDB Hello World Example
  5. Java MongoDB Get Collection from Database
  6. Java MongoDB Inserting a Document to Database
  7. Java MongoDB Deleting a Document to Database
  8. Java MongoDB Updating a Document to Database
  9. Java MongoDB Query a Document to Database
  10. Java MongoDB Convert JSON data to DBObject
  11. Authentication to MongoDB with Java
  12. Spring Data MongoDB Examples

References-

  1. Download MongoDB
  2. Install MongoDB on Windows
  3. Java development with MongoDB
  4. Spring data for MongoDB
  5. Spring data for MongoDB documentation
Next

4 Comments

  1. Anonymous December 13, 2013
  2. Dinesh December 14, 2013
  3. Dinesh December 14, 2013
  4. Dinesh December 14, 2013