Categories: MongoDB

MongoDB Tutorial – Introduction to MongoDB

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
Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

2 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

2 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

2 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

2 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

2 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

3 years ago