SlideShare a Scribd company logo
Seminar Report: MongoDB
by
ADITYA, (Roll Number)
Submitted to the Department of Computer Science
in partial fulfilment of the requirements
for the degree of
Bachelor of Technology
IEC College Of Engineering and Technology
Greater Noida (U.P.)
A.K.T.U University
MAY, 2018
SUBMITTED TO: SUBMITTED BY:
MongoDB Database
Welcome to MongoDB Report
FOR GIANT IDEA
MongoDB
A Giant Database
Computer Science Department
May, 2018
MongoDB Database
Preface
MongoDB is an extremely versatile NoSQL database that offers performance, scalability,
and reliability of data. It has become one of the leading NoSQL database systems used for
storing extremely large datasets. In addition to this, the fact that it is open source makes it
the perfect candidate for any project from prototyping a minimal viable product to storing
millions of complex documents, MongoDB is clearly emerging as the go-to database system.
This report aims to help the reader in operating and managing MongoDB systems. The
contents of this report are divided into sections covering all the core aspects of administering
MongoDB systems. The primary goal of this book is not to duplicate the MongoDB
documentation, but to gently nudge the reader towards topics that they are often overlooked
when designing MongoDB systems.
Prerequisite
Before learning MongoDB, you must have the basic knowledge of SQL and OOPs.
MongoDB Database
ACKNOWLEDGEMENT
It gives us a great sense of pleasure to present the report of the B. Tech Seminar undertaken
during B. Tech. Third Year. We owe special debt of gratitude to Professor ---------------,
Department of -----------------, IEC College of Engineering and Technology , for his constant
support and guidance throughout the course of our work. His sincerity, thoroughness and
perseverance have been a constant source of inspiration for us. It is only his cognizant efforts
that our endeavors have seen light of the day.
We also take the opportunity to acknowledge the contribution of-----------------------, Head,
Department of -------------------------- for his full support and assistance .We also do not like
to miss the opportunity to acknowledge the contribution of all faculty members of the
department for their kind assistance and cooperation during the development of our project.
Last but not the least, we acknowledge our friends for their contribution in the completion
of the project.
Signature :
Name :
Roll No. :
Date :
MongoDB Database
pg. 4
TABLE OF CONTENTS
Page
Preface (i)
Acknowledgement (ii)
1. Installation and Configuration
1.1 How to install MongoDBon Windows ……………………………………………………………… 5
1.2 How to download MongoDB ……………………………………………………………………………. 5
1.3 MongoDB for windows Server 2008 R2 edition ……………………………………………….. 5
1.4 MongoDB for 64-bitWindows …………………………………………………………………………. 5
1.5 MongoDB for 32-bitWindows …………………………………………………………………………. 5
1.6 How to install thedownloaded file………………………………………………………………….. 6
1.7 How to set up the MongoDB environment ………………………………………………………. 6
1.8 How to configure directory and files ………………………………………………………………… 7
2. Introduction and History
2.1 Introduction …………………………………………………………………………………………………….. 8
2.2 What is Document based storage ……………………………………………………………………. 8
2.3 Purposeto build MongoDB ……………………………………………………………………………… 9
2.4 Main purposeto build MongoDB …………………………………………………………………….. 9
2.5 Key points of MongoDB …………………………………………………………………………………… 9
2.6 History of MongoDB ………………………………………………………………………………………… 9
2.7 Example of document oriented database………………………………………………………… 10
2.8 Features of MongoDB ……………………………………………………………………………………… 10
2.9 No SQL database…………………………………………………………………………………………….. 11
2.10 History behind the creation of NoSQL database…………………………………………….. 12
2.11 Advantage of NoSQL ………………………………………………………………………………………. 12
2.12 MongoDB Advantage ……………………………………………………………………………………… 12
2.13 Distinctivefeatures of MongoDB …………………………………………………………………… 13
2.14 Where MongoDB should be used ……………………………………………………………………. 13
2.15 Performance analysis of MongoDB and RDMS ………………………………………………… 13
3. Database
3.1 DatabaseCreate and Drop ………………………………………………………………………………. 15
3.2 Creating a Database………………………………………………………………………………………… 15
4. Collection
4.1 Creating a Collection ……………………………………………………………………………………….. 18
4.2 Creating a Capped Collection …………………………………………………………………………… 19
4.3 Drop a Collection ……………………………………………………………………………………………… 19
5. Curd Operations
5.1 Curd Operations in MongoDB …………………………………………………………………………… 20
5.2 Insertinga document into a collection (Create) ………………………………………………… 20
5.3 Querying a document from a collection (Read) ………………………………………………… 21
5.4 Updating a document in a Collection (Update) …………………………………………………. 22
5.5 Removing an entry the collection (Delete) ………………………………………………………… 23
6. Connectivity
6.1 Java MongoDB Connectivity …………………………………………………………………………….. 24
6.2 Followthe Steps …….………………………………………………………………………………………… 24
6.3 Project Structure …………………………………………………………………………………………….. 26
MongoDB Database
pg. 5
INSTALLATION AND CONFIGURATION
How to install MongoDB on Windows
Firstly, you will have to download the latest release of MongoDB:
How to download MongoDB
You can download an appropriate version of MongoDB which your system supports, from
the link "http://www.mongodb.org/downloads" to install the MongoDB on Windows.
You should choose correct version of MongoDB according to your computer's Window. If
you are not sure what Window version are you using, open your command prompt and
execute this command:
1. C: wmic os get osarchitecture
OSArchitecture
64 bits
C: >
Note: MongoDB does not support Window XP.
MongoDB for Windows Server 2008 R2 edition
This version of MongoDB runs only on Window Server 2008 R2, Window7 64 bit, and the
newer version of windows. You can't operate it on older version of windows.
MongoDB for 64-bit Windows
This version of MongoDB runs only on newer version of Windows contains 64-bit operating
system.
for example: Window Server 2008 R2, Window 7 64 bit etc.
MongoDB for 32-bit Windows
This version of MongoDB runs on only 32-bit windows. 32-bit version of MongoDB is
generally used in testing and development purposes because it supports databases smaller
than 2 GB.
How to install the downloaded file
In Window explorer, locate the downloaded MongoDB msi file, double click on that file and
follow the instructions appears on the screen. These instructions will guide you to complete
the installation process.
MongoDB Database
pg. 6
Note: If you want to move the MongoDB folder from default position to another position, it
is necessary to issue the move command as an administrator. let us take an example to move
the folder to C: mongodb:
1. Select Start Menu > All Programs > Accessories
You can install MongoDB in any folder because it is self-contained and does not have any
other system dependency.
How to set up the MongoDB environment
A data directory is required in MongoDB to store all the information. Its by default data
directory path is datadb. you can create this folder by command prompt.
1. mddatadb
For example:
If you want to start MongoDB, run mongod.exe
You can do it from command prompt.
1. C:Program FilesMongoDBbinmongod.exe
This will start the mongoDB database process. If you get a message "waiting for connection"
in the console output, it indicates that the mongodb.exe process is running successfully.
For example:
When you connect to the MongoDB through the mongo.exe shell, you should follow these
steps:
1. Open another command prompt.
2. At the time of connecting, specify the data directory if necessary.
Note: If you use the default data directory while MongoDB installation, there is no need to
specify the data directory.
For example:
1. C:mongodbbinmongo.exe
If you use the different data directory while MongoDB installation, specify the directory
when connecting.
For example:
MongoDB Database
pg. 7
1. C:mongodbbinmongod.exe-- dbpath d:testmongodbdata
If you have spaces in your path, enclose the entire path in double space.
For example:
1. C:mongodbbinmongod.exe-- dbpath "d:  testmongodbdata"
How to configure directory and files
First to create a configuration file and a directory path for MongoDB log output after
that create a specific directory for MongoDB log files.
MongoDB Database
pg. 8
INTRODUCTION AND HISTORY
Introduction
MongoDB is a NoSQL database which stores the data in form of key-value pairs. It is
an Open Source, Document Database which provides high performance and scalability
along with data modelling and data management of huge sets of data in an enterprise
application.
MongoDB also provides the feature of Auto-Scaling. Since, MongoDB is a cross platform
database and can be installed across different platforms like Windows, Linux etc.
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.
What is Document based storage?
A Document is nothing but a data structure with name-value pairs like in JSON. It is very
easy to map any custom Object of any programming language with a MongoDB Document.
For example: Student object has attributes name, rollno and subjects, where subjects are a
List.
Document for Student in MongoDB will be like:
{
name : "Stduytonight",
rollno : 1,
subjects : ["C Language", "C++", "Core Java"]
}
We can see, Documents are actually JSON representation of custom Objects. Also, excessive
JOINS can be avoided by saving data in form of Arrays and Documents(Embedded) inside
a Document.
MongoDB Database
pg. 9
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:
o Scalability
o Performance
o High Availability
o Scaling from single server deployments to large, complex multi-site architectures.
Key points of MongoDB
o Develop Faster
o Deploy Easier
o 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 New York 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.
MongoDB Database
pg. 10
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 Database
pg. 11
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:
o JSON data model with dynamic schemas
o Auto-sharding for horizontal scalability
o 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 thoroughly.
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.
MongoDB Database
pg. 12
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 gets a
problem that it could not handle big data, due to this problem there was a need of database
which can handle every type of problems then NoSQL database was developed.
Advantages of NoSQL
o It supports query language.
o It provides fast performance.
o 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
o MongoDB is schema less. It is a document database in which one collection holds
different documents.
o There may be difference between number of fields, content and size of the
document from one to other.
o Structure of a single object is clear in MongoDB.
o There are no complex joins in MongoDB.
o MongoDB provides the facility of deep query because it supports a powerful
dynamic query on documents.
o It is very easy to scale.
MongoDB Database
pg. 13
o It uses internal memory for storing working sets and this is the reason of its fast
access.
Distinctive features of MongoDB
o Easy to use
o Light Weight
o Extremely faster than RDBMS
Where MongoDB should be used
o Big and complex data
o Mobile and social infrastructure
o Content management and delivery
o User data management
o Data hub
Performance analysis of MongoDB and RDBMS
o In relational database (RDBMS) tables are using as storing elements, while in
MongoDB collection is used.
o 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.
o MongoDB is almost 100 times faster than traditional database systems.
MongoDB Datatypes
Following is a list of usable data types in MongoDB.
Data Types Description
String String is the most commonly used datatype. It is used to store data. A string must be UTF 8 valid in
mongodb.
Integer Integer is used to store the numeric value. It can be 32 bit or 64 bit depending on the server you are
using.
Boolean This datatype is used to store boolean values. It just show s YES/NO values.
MongoDB Database
pg. 14
Double Double datatype stores floating point values.
Min/Max
Keys
This datatype compares a value against the low est and highest bson elements.
Arrays This datatype is used to store a list or multiple values into a single key.
Object Object datatype is used for embedded documents.
Null It is used to store null values.
Symbol It is generally used for languages that use a specific type.
Date This datatype stores the current date or time in unix time format. It makes you possible to specify your
ow n date time by creating object of date and pass the value of date, month, year into it.
MongoDB Database
pg. 15
DATABASE
Database Create and Drop
In this lesson we will learn how to create and drop a Database in MongoDB.
Creating a Database
Open the command prompt and navigate to the /bin folder of the MongoDB using
the cd command and execute the command mongodb there. This will initiate the MongoDB
server. We have to keep this command prompt window alive, as this is running MongoDB.
To stop the MongoDB server, simply enter exit and press Enter.
Now, open another command prompt and navigate to the /bin folder of the MongoDB again
and execute the command mongo. This will open up the client to run the MongoDB
commands.

In the command prompt window in which we ran the mongo command, after successfully
connecting to the mongodb, just type the command the following:
use database_name
This will create a new database with the name database_name if there is no database
already present with the same name. If a database already exists with the mentioned name,
then it just connects to that database.

In the above picture, it creates a new database called mynewdatabase and will also connect
to the same.
MongoDB Database
pg. 16
To check the current connected database, type in db in the command prompt window, and
you will get the name of the current database as result.
To see the list of all the databases in MongoDB, use command show dbs
Please note that the newly created database mynewdatabase has not been listed after
running the above command. This is because, no records have been inserted into that
database yet. Just insert one record and then run the command again as shown below:
To Insert data, run the following command. Don’t worry about it, we will learn this in
detail in next lessons.
db.student.insert({ name : "Viraj" })
NOTE: In MongoDB, test will be the default database. If no database is created, then all
the data will
be stored in the test database.
Drop a Database
First check the list of databases available as shown below, using the show dbs command.
MongoDB Database
pg. 17
If the newly created database mynewdatabase has to be dropped(deleted). Run the below
command to delete the database. Before deleting the database, connect to the required
database which is to be deleted.
db.dropDatabase()
Now again check the list of databases, to verify whether the database is deleted or not.
Note that the database mynewdatabase has been deleted and hence, it will not be listed in
the list of the databases.
MongoDB Database
pg. 18
COLLECTION
Creating a Collection
In MongoDB a collection is automatically created when it is referenced in any command.
For example, if you run an insert command:
db.student.insert({
name: "Viraj"
})
Above command will create a collection named student if it doesn't exist already in the
database. But we can explicitly create a collection using the createCollection() command.
The syntax of createCollection method is:
db.createCollection(name, options)
In the above command, name will be the name of the collection and options is a document
which can be used to specify configurations for the collection.
options parameter is optional, and you can simply create a collection by just providing a
name for the collection. But if you want to configure your collection, you can use various
options available to do so. Following are the available configuration options for creating a
collection in MongoDB :
Field Type Description
capped boolean (Optional) To create a capped collection, where in we
specify the maximum size or document counts to
prevent it from growing beyond a set maximum value.
size number (Optional) To specify the maximum size in bytes for a
capped collection. If a collection is capped and reaches
its maximum size limit, MongoDB then removes older
documents from it to make space for new.
max number (Optional) This can be used to specify the maximum
number of documents allowed in a capped collection.
validator document (Optional) Validates any document inserted or updated
against provided validation rules.
MongoDB Database
pg. 19
validationLevel string (Optional) This is used to define how strictly validation
rules must be applied to existing documents during an
update.
Available values are:
off No validation for inserts or updates.
strict This is the default value for this option. This
instructs MongoDB to apply validation rules to all
inserts and updates.
moderate This is used when we want to apply
validation rules to inserts and updates on only the
existing valid documents and not on the existing
invalid documents.
validationAction string (Optional) This can be used to set the action to be taken
upon validation i.e. if any document fails the set
validation then whether to show error or
just warn about the violations. Default value is error.
Creating a Capped Collection
We can create a capped collection using the following command.
db.createCollection("student", { capped : true, size : 5242880, max : 5000 } )
This will create a collection named student, with maximum size of 5 megabytes and
maximum of 5000 documents.
Drop a Collection
Any collection in a database in MongoDB can be dropped easily using the following
command:
db.collection_name.drop()
drop() method will return true is the collection is dropped successfully, else it will return
false.
MongoDB Database
pg. 20
CURD OPERATIONS
CRUD Operationsin MongoDB
CRUD operations refer to the basic Insert, Read, Update and Delete operations. In the
previous chapter, we learnt about how to create a database and drop the database in
MongoDB. Now, let us learn how to perform CRUD (Create/Read/Update/Delete)
operations in MongoDB.

Inserting a document into a collection (Create)
The command db.collection.insert() will perform an insert operation into a collection of a
document.
Let us insert a document to a student collection. You must be connected to a database for
doing any insert. It is done as follows:
db.student.insert({
regNo: "3014",
name: "Test Student",
course: {
courseName: "MCA",
duration: "3 Years"
},
address: {
city: "Bangalore",
state: "KA",
country: "India"
}
})
MongoDB Database
pg. 21
Note: that an entry has been made into the collection called student.
Querying a document from a collection (Read)
To retrieve (Select) the inserted document, run the below command. The find() command
will retrieve all the documents of the given collection.
db.collection_name.find()
NOTE: Please observe that the record retrieved contains an attribute called _id with some
unique identifier value called ObjectId which acts as a document identifier.
If a record is to be retrieved based on some criteria, the find() method should be called
passing parameters, then the record will be retrieved based on the attributes specified.
db.collection_name.find({"fieldname":"value"})
MongoDB Database
pg. 22
For Example: Let us retrieve the record from the student collection where the
attribute regNo is 3014and the query for the same is as shown below:
db.students.find({"regNo":"3014"})
Updating a document in a collection (Update)
In order to update specific field values of a collection in MongoDB, run the below query.
db.collection_name.update()
update() method specified above will take the fieldname and the new value as argument to
update a document.
Let us update the attribute name of the collection student for the document
with regNo 3014.
db.student.update({
"regNo": "3014"
},
$set:
{
"name":"Viraj"
})
You will see the following in the Command Prompt:
MongoDB Database
pg. 23
Removing an entry from the collection (Delete)
Let us now look into the deleting an entry from a collection. In order to delete an entry
from a collection, run the command as shown below:
db.collection_name.remove({"fieldname":"value"})
For Example: db.student.remove({"regNo":"3014"})
Note that after running the remove() method, the entry has been deleted from the student
collection.
MongoDB Database
pg. 24
CONNECTIVITY
Java MongoDB Connectivity
To connect with MongoDB database, Java project includes the following steps. Here, we are
creating a maven project and providing dependency for the mongodb-driver.
Follow the Steps:
1) Create a Maven Project
2) Add Dependency to POM file
// pom.xml
1. <? xml version="1.0" encoding="UTF-8"?>
2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/200
1/XMLSchema-
instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.o
rg/xsd/maven-4.0.0.xsd">
3. <modelVersion>4.0.0</modelVersion>
4. <groupId>com.javatpoint</groupId>
5. <artifactId>java-mongo-db</artifactId>
6. <version>1.0-SNAPSHOT</version>
7. <packaging>jar</packaging>
8. <properties>
9. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10. <maven.compiler.source>1.8</maven.compiler.source>
11. <maven.compiler.target>1.8</maven.compiler.target>
12. </properties>
13. <name>java-mongodb</name>
14. <dependencies>
MongoDB Database
pg. 25
15. <dependency>
16. <groupId>org.mongodb</groupId>
17. <artifactId>mongodb-driver</artifactId>
18. <version>3.4.2</version>
19. </dependency>
20. </dependencies>
21. </project>
3) Create Java File
Create a Java file and write code to create connection.
// JavaMongoDemo.java
1. package com.javatpoint.java.mongo.db;
2. import com.mongodb.MongoClient;
3. import com.mongodb.client.MongoCollection;
4. import com.mongodb.client.MongoDatabase;
5. import org.bson.Document;
6. public class JavaMongoDemo {
7. public static void main(String[] args){
8. try{
9. //---------- Connecting DataBase -------------------------//
10. MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
11. //---------- Creating DataBase ---------------------------//
12. MongoDatabase db = mongoClient.getDatabase("javatpoint");
13. //---------- Creating Collection -------------------------//
14. MongoCollection<Document> table = db.getCollection("employee");
15. //---------- Creating Document ---------------------------//
16. Document doc = new Document("name", "Peter John");
17. doc.append("id",12);
18. //----------- Inserting Data ------------------------------//
19. table.insertOne(doc);
20. }catch(Exception e){
21. System.out.println(e);
22. }
23. }
24. }
MongoDB Database
pg. 26
4) Build Dependency to load JAR
Project Structure
Finally, our project structure look like this.
5) Enter into Mongo Shell
Make sure, we have mongoDB installed. After installing, enter into mongo shell by typing
the following command.
MongoDB Database
pg. 27
$ mongo
Databases
We can see available databases by using the following command.
> show dbs
We can see that there is no database available. let's create a database.
Run Java File
MongoDB Database
pg. 28
Run this file to create database.
Database
Check MongoDB again to see the available databases.
See, a database javatpoint is created.
Collection
See, the created collection employee.
Record
See the inserted record.
Well, we can see that the Java program is executing fine and we can also perform other
databases operations as well.
Ad

More Related Content

What's hot (20)

Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
Surya937648
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
Tata Consultancy Services
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
HabileLabs
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
Bishal Khanal
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
Lee Theobald
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
MongoDB
 
Mongo db intro.pptx
Mongo db intro.pptxMongo db intro.pptx
Mongo db intro.pptx
JWORKS powered by Ordina
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
valuebound
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
NodeXperts
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
Jaya Naresh Kovela
 
Introducing MongoDB Atlas
Introducing MongoDB AtlasIntroducing MongoDB Atlas
Introducing MongoDB Atlas
MongoDB
 
NoSQL Data Architecture Patterns
NoSQL Data ArchitecturePatternsNoSQL Data ArchitecturePatterns
NoSQL Data Architecture Patterns
Maynooth University
 
PPT on Hadoop
PPT on HadoopPPT on Hadoop
PPT on Hadoop
Shubham Parmar
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
César Trigo
 
Map Reduce
Map ReduceMap Reduce
Map Reduce
Prashant Gupta
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
neela madheswari
 
Open Metadata and Governance with Apache Atlas
Open Metadata and Governance with Apache AtlasOpen Metadata and Governance with Apache Atlas
Open Metadata and Governance with Apache Atlas
DataWorks Summit
 
An Overview of Apache Cassandra
An Overview of Apache CassandraAn Overview of Apache Cassandra
An Overview of Apache Cassandra
DataStax
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Mike Dirolf
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
Surya937648
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
HabileLabs
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
Bishal Khanal
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
Lee Theobald
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
MongoDB
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
valuebound
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
NodeXperts
 
Introducing MongoDB Atlas
Introducing MongoDB AtlasIntroducing MongoDB Atlas
Introducing MongoDB Atlas
MongoDB
 
NoSQL Data Architecture Patterns
NoSQL Data ArchitecturePatternsNoSQL Data ArchitecturePatterns
NoSQL Data Architecture Patterns
Maynooth University
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
César Trigo
 
Open Metadata and Governance with Apache Atlas
Open Metadata and Governance with Apache AtlasOpen Metadata and Governance with Apache Atlas
Open Metadata and Governance with Apache Atlas
DataWorks Summit
 
An Overview of Apache Cassandra
An Overview of Apache CassandraAn Overview of Apache Cassandra
An Overview of Apache Cassandra
DataStax
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Mike Dirolf
 

Similar to Mongo db report (20)

how_can_businesses_address_storage_issues_using_mongodb.pdf
how_can_businesses_address_storage_issues_using_mongodb.pdfhow_can_businesses_address_storage_issues_using_mongodb.pdf
how_can_businesses_address_storage_issues_using_mongodb.pdf
sarah david
 
how_can_businesses_address_storage_issues_using_mongodb.pptx
how_can_businesses_address_storage_issues_using_mongodb.pptxhow_can_businesses_address_storage_issues_using_mongodb.pptx
how_can_businesses_address_storage_issues_using_mongodb.pptx
sarah david
 
Experiment no 1
Experiment no 1Experiment no 1
Experiment no 1
Ankit Dubey
 
Mongo db reference manual
Mongo db reference manualMongo db reference manual
Mongo db reference manual
Deysi Gmarra
 
Mongo db reference-manual
Mongo db reference-manualMongo db reference-manual
Mongo db reference-manual
Dan Llimpe
 
Mdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchMdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_search
Daniel M. Farrell
 
3 scenarios when to use MongoDB!
3 scenarios when to use MongoDB!3 scenarios when to use MongoDB!
3 scenarios when to use MongoDB!
Edureka!
 
Mongodb
MongodbMongodb
Mongodb
ichangbai
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEAN
Troy Miles
 
upload.txt
upload.txtupload.txt
upload.txt
IshNexus
 
edit and approve 2
edit and approve 2edit and approve 2
edit and approve 2
Bhavani Testone
 
MongoDB
MongoDBMongoDB
MongoDB
wiTTyMinds1
 
upload.txt
upload.txtupload.txt
upload.txt
Bhavani Testone
 
uploaded at 10:56
uploaded at 10:56uploaded at 10:56
uploaded at 10:56
Roopa slideshare
 
upload.txt
upload.txtupload.txt
upload.txt
Roopa slideshare
 
upload.txt
upload.txtupload.txt
upload.txt
Roopa slideshare
 
MongoDB Developer's Notebook, March 2016 -- MongoDB Connector for Business In...
MongoDB Developer's Notebook, March 2016 -- MongoDB Connector for Business In...MongoDB Developer's Notebook, March 2016 -- MongoDB Connector for Business In...
MongoDB Developer's Notebook, March 2016 -- MongoDB Connector for Business In...
Daniel M. Farrell
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
Mongodb By Vipin
Mongodb By VipinMongodb By Vipin
Mongodb By Vipin
Vipin Mundayad
 
How do you connect your mongo db database with node.js
How do you connect your mongo db database with node.js How do you connect your mongo db database with node.js
How do you connect your mongo db database with node.js
MoonTechnolabsPvtLtd
 
how_can_businesses_address_storage_issues_using_mongodb.pdf
how_can_businesses_address_storage_issues_using_mongodb.pdfhow_can_businesses_address_storage_issues_using_mongodb.pdf
how_can_businesses_address_storage_issues_using_mongodb.pdf
sarah david
 
how_can_businesses_address_storage_issues_using_mongodb.pptx
how_can_businesses_address_storage_issues_using_mongodb.pptxhow_can_businesses_address_storage_issues_using_mongodb.pptx
how_can_businesses_address_storage_issues_using_mongodb.pptx
sarah david
 
Mongo db reference manual
Mongo db reference manualMongo db reference manual
Mongo db reference manual
Deysi Gmarra
 
Mongo db reference-manual
Mongo db reference-manualMongo db reference-manual
Mongo db reference-manual
Dan Llimpe
 
Mdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchMdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_search
Daniel M. Farrell
 
3 scenarios when to use MongoDB!
3 scenarios when to use MongoDB!3 scenarios when to use MongoDB!
3 scenarios when to use MongoDB!
Edureka!
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEAN
Troy Miles
 
upload.txt
upload.txtupload.txt
upload.txt
IshNexus
 
MongoDB Developer's Notebook, March 2016 -- MongoDB Connector for Business In...
MongoDB Developer's Notebook, March 2016 -- MongoDB Connector for Business In...MongoDB Developer's Notebook, March 2016 -- MongoDB Connector for Business In...
MongoDB Developer's Notebook, March 2016 -- MongoDB Connector for Business In...
Daniel M. Farrell
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
How do you connect your mongo db database with node.js
How do you connect your mongo db database with node.js How do you connect your mongo db database with node.js
How do you connect your mongo db database with node.js
MoonTechnolabsPvtLtd
 
Ad

Recently uploaded (20)

Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Ad

Mongo db report

  • 1. Seminar Report: MongoDB by ADITYA, (Roll Number) Submitted to the Department of Computer Science in partial fulfilment of the requirements for the degree of Bachelor of Technology IEC College Of Engineering and Technology Greater Noida (U.P.) A.K.T.U University MAY, 2018 SUBMITTED TO: SUBMITTED BY:
  • 2. MongoDB Database Welcome to MongoDB Report FOR GIANT IDEA MongoDB A Giant Database Computer Science Department May, 2018
  • 3. MongoDB Database Preface MongoDB is an extremely versatile NoSQL database that offers performance, scalability, and reliability of data. It has become one of the leading NoSQL database systems used for storing extremely large datasets. In addition to this, the fact that it is open source makes it the perfect candidate for any project from prototyping a minimal viable product to storing millions of complex documents, MongoDB is clearly emerging as the go-to database system. This report aims to help the reader in operating and managing MongoDB systems. The contents of this report are divided into sections covering all the core aspects of administering MongoDB systems. The primary goal of this book is not to duplicate the MongoDB documentation, but to gently nudge the reader towards topics that they are often overlooked when designing MongoDB systems. Prerequisite Before learning MongoDB, you must have the basic knowledge of SQL and OOPs.
  • 4. MongoDB Database ACKNOWLEDGEMENT It gives us a great sense of pleasure to present the report of the B. Tech Seminar undertaken during B. Tech. Third Year. We owe special debt of gratitude to Professor ---------------, Department of -----------------, IEC College of Engineering and Technology , for his constant support and guidance throughout the course of our work. His sincerity, thoroughness and perseverance have been a constant source of inspiration for us. It is only his cognizant efforts that our endeavors have seen light of the day. We also take the opportunity to acknowledge the contribution of-----------------------, Head, Department of -------------------------- for his full support and assistance .We also do not like to miss the opportunity to acknowledge the contribution of all faculty members of the department for their kind assistance and cooperation during the development of our project. Last but not the least, we acknowledge our friends for their contribution in the completion of the project. Signature : Name : Roll No. : Date :
  • 5. MongoDB Database pg. 4 TABLE OF CONTENTS Page Preface (i) Acknowledgement (ii) 1. Installation and Configuration 1.1 How to install MongoDBon Windows ……………………………………………………………… 5 1.2 How to download MongoDB ……………………………………………………………………………. 5 1.3 MongoDB for windows Server 2008 R2 edition ……………………………………………….. 5 1.4 MongoDB for 64-bitWindows …………………………………………………………………………. 5 1.5 MongoDB for 32-bitWindows …………………………………………………………………………. 5 1.6 How to install thedownloaded file………………………………………………………………….. 6 1.7 How to set up the MongoDB environment ………………………………………………………. 6 1.8 How to configure directory and files ………………………………………………………………… 7 2. Introduction and History 2.1 Introduction …………………………………………………………………………………………………….. 8 2.2 What is Document based storage ……………………………………………………………………. 8 2.3 Purposeto build MongoDB ……………………………………………………………………………… 9 2.4 Main purposeto build MongoDB …………………………………………………………………….. 9 2.5 Key points of MongoDB …………………………………………………………………………………… 9 2.6 History of MongoDB ………………………………………………………………………………………… 9 2.7 Example of document oriented database………………………………………………………… 10 2.8 Features of MongoDB ……………………………………………………………………………………… 10 2.9 No SQL database…………………………………………………………………………………………….. 11 2.10 History behind the creation of NoSQL database…………………………………………….. 12 2.11 Advantage of NoSQL ………………………………………………………………………………………. 12 2.12 MongoDB Advantage ……………………………………………………………………………………… 12 2.13 Distinctivefeatures of MongoDB …………………………………………………………………… 13 2.14 Where MongoDB should be used ……………………………………………………………………. 13 2.15 Performance analysis of MongoDB and RDMS ………………………………………………… 13 3. Database 3.1 DatabaseCreate and Drop ………………………………………………………………………………. 15 3.2 Creating a Database………………………………………………………………………………………… 15 4. Collection 4.1 Creating a Collection ……………………………………………………………………………………….. 18 4.2 Creating a Capped Collection …………………………………………………………………………… 19 4.3 Drop a Collection ……………………………………………………………………………………………… 19 5. Curd Operations 5.1 Curd Operations in MongoDB …………………………………………………………………………… 20 5.2 Insertinga document into a collection (Create) ………………………………………………… 20 5.3 Querying a document from a collection (Read) ………………………………………………… 21 5.4 Updating a document in a Collection (Update) …………………………………………………. 22 5.5 Removing an entry the collection (Delete) ………………………………………………………… 23 6. Connectivity 6.1 Java MongoDB Connectivity …………………………………………………………………………….. 24 6.2 Followthe Steps …….………………………………………………………………………………………… 24 6.3 Project Structure …………………………………………………………………………………………….. 26
  • 6. MongoDB Database pg. 5 INSTALLATION AND CONFIGURATION How to install MongoDB on Windows Firstly, you will have to download the latest release of MongoDB: How to download MongoDB You can download an appropriate version of MongoDB which your system supports, from the link "http://www.mongodb.org/downloads" to install the MongoDB on Windows. You should choose correct version of MongoDB according to your computer's Window. If you are not sure what Window version are you using, open your command prompt and execute this command: 1. C: wmic os get osarchitecture OSArchitecture 64 bits C: > Note: MongoDB does not support Window XP. MongoDB for Windows Server 2008 R2 edition This version of MongoDB runs only on Window Server 2008 R2, Window7 64 bit, and the newer version of windows. You can't operate it on older version of windows. MongoDB for 64-bit Windows This version of MongoDB runs only on newer version of Windows contains 64-bit operating system. for example: Window Server 2008 R2, Window 7 64 bit etc. MongoDB for 32-bit Windows This version of MongoDB runs on only 32-bit windows. 32-bit version of MongoDB is generally used in testing and development purposes because it supports databases smaller than 2 GB. How to install the downloaded file In Window explorer, locate the downloaded MongoDB msi file, double click on that file and follow the instructions appears on the screen. These instructions will guide you to complete the installation process.
  • 7. MongoDB Database pg. 6 Note: If you want to move the MongoDB folder from default position to another position, it is necessary to issue the move command as an administrator. let us take an example to move the folder to C: mongodb: 1. Select Start Menu > All Programs > Accessories You can install MongoDB in any folder because it is self-contained and does not have any other system dependency. How to set up the MongoDB environment A data directory is required in MongoDB to store all the information. Its by default data directory path is datadb. you can create this folder by command prompt. 1. mddatadb For example: If you want to start MongoDB, run mongod.exe You can do it from command prompt. 1. C:Program FilesMongoDBbinmongod.exe This will start the mongoDB database process. If you get a message "waiting for connection" in the console output, it indicates that the mongodb.exe process is running successfully. For example: When you connect to the MongoDB through the mongo.exe shell, you should follow these steps: 1. Open another command prompt. 2. At the time of connecting, specify the data directory if necessary. Note: If you use the default data directory while MongoDB installation, there is no need to specify the data directory. For example: 1. C:mongodbbinmongo.exe If you use the different data directory while MongoDB installation, specify the directory when connecting. For example:
  • 8. MongoDB Database pg. 7 1. C:mongodbbinmongod.exe-- dbpath d:testmongodbdata If you have spaces in your path, enclose the entire path in double space. For example: 1. C:mongodbbinmongod.exe-- dbpath "d: testmongodbdata" How to configure directory and files First to create a configuration file and a directory path for MongoDB log output after that create a specific directory for MongoDB log files.
  • 9. MongoDB Database pg. 8 INTRODUCTION AND HISTORY Introduction MongoDB is a NoSQL database which stores the data in form of key-value pairs. It is an Open Source, Document Database which provides high performance and scalability along with data modelling and data management of huge sets of data in an enterprise application. MongoDB also provides the feature of Auto-Scaling. Since, MongoDB is a cross platform database and can be installed across different platforms like Windows, Linux etc. 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. What is Document based storage? A Document is nothing but a data structure with name-value pairs like in JSON. It is very easy to map any custom Object of any programming language with a MongoDB Document. For example: Student object has attributes name, rollno and subjects, where subjects are a List. Document for Student in MongoDB will be like: { name : "Stduytonight", rollno : 1, subjects : ["C Language", "C++", "Core Java"] } We can see, Documents are actually JSON representation of custom Objects. Also, excessive JOINS can be avoided by saving data in form of Arrays and Documents(Embedded) inside a Document.
  • 10. MongoDB Database pg. 9 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: o Scalability o Performance o High Availability o Scaling from single server deployments to large, complex multi-site architectures. Key points of MongoDB o Develop Faster o Deploy Easier o 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 New York 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.
  • 11. MongoDB Database pg. 10 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
  • 12. MongoDB Database pg. 11 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: o JSON data model with dynamic schemas o Auto-sharding for horizontal scalability o 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 thoroughly. 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.
  • 13. MongoDB Database pg. 12 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 gets a problem that it could not handle big data, due to this problem there was a need of database which can handle every type of problems then NoSQL database was developed. Advantages of NoSQL o It supports query language. o It provides fast performance. o 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 o MongoDB is schema less. It is a document database in which one collection holds different documents. o There may be difference between number of fields, content and size of the document from one to other. o Structure of a single object is clear in MongoDB. o There are no complex joins in MongoDB. o MongoDB provides the facility of deep query because it supports a powerful dynamic query on documents. o It is very easy to scale.
  • 14. MongoDB Database pg. 13 o It uses internal memory for storing working sets and this is the reason of its fast access. Distinctive features of MongoDB o Easy to use o Light Weight o Extremely faster than RDBMS Where MongoDB should be used o Big and complex data o Mobile and social infrastructure o Content management and delivery o User data management o Data hub Performance analysis of MongoDB and RDBMS o In relational database (RDBMS) tables are using as storing elements, while in MongoDB collection is used. o 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. o MongoDB is almost 100 times faster than traditional database systems. MongoDB Datatypes Following is a list of usable data types in MongoDB. Data Types Description String String is the most commonly used datatype. It is used to store data. A string must be UTF 8 valid in mongodb. Integer Integer is used to store the numeric value. It can be 32 bit or 64 bit depending on the server you are using. Boolean This datatype is used to store boolean values. It just show s YES/NO values.
  • 15. MongoDB Database pg. 14 Double Double datatype stores floating point values. Min/Max Keys This datatype compares a value against the low est and highest bson elements. Arrays This datatype is used to store a list or multiple values into a single key. Object Object datatype is used for embedded documents. Null It is used to store null values. Symbol It is generally used for languages that use a specific type. Date This datatype stores the current date or time in unix time format. It makes you possible to specify your ow n date time by creating object of date and pass the value of date, month, year into it.
  • 16. MongoDB Database pg. 15 DATABASE Database Create and Drop In this lesson we will learn how to create and drop a Database in MongoDB. Creating a Database Open the command prompt and navigate to the /bin folder of the MongoDB using the cd command and execute the command mongodb there. This will initiate the MongoDB server. We have to keep this command prompt window alive, as this is running MongoDB. To stop the MongoDB server, simply enter exit and press Enter. Now, open another command prompt and navigate to the /bin folder of the MongoDB again and execute the command mongo. This will open up the client to run the MongoDB commands.
 In the command prompt window in which we ran the mongo command, after successfully connecting to the mongodb, just type the command the following: use database_name This will create a new database with the name database_name if there is no database already present with the same name. If a database already exists with the mentioned name, then it just connects to that database.
 In the above picture, it creates a new database called mynewdatabase and will also connect to the same.
  • 17. MongoDB Database pg. 16 To check the current connected database, type in db in the command prompt window, and you will get the name of the current database as result. To see the list of all the databases in MongoDB, use command show dbs Please note that the newly created database mynewdatabase has not been listed after running the above command. This is because, no records have been inserted into that database yet. Just insert one record and then run the command again as shown below: To Insert data, run the following command. Don’t worry about it, we will learn this in detail in next lessons. db.student.insert({ name : "Viraj" }) NOTE: In MongoDB, test will be the default database. If no database is created, then all the data will be stored in the test database. Drop a Database First check the list of databases available as shown below, using the show dbs command.
  • 18. MongoDB Database pg. 17 If the newly created database mynewdatabase has to be dropped(deleted). Run the below command to delete the database. Before deleting the database, connect to the required database which is to be deleted. db.dropDatabase() Now again check the list of databases, to verify whether the database is deleted or not. Note that the database mynewdatabase has been deleted and hence, it will not be listed in the list of the databases.
  • 19. MongoDB Database pg. 18 COLLECTION Creating a Collection In MongoDB a collection is automatically created when it is referenced in any command. For example, if you run an insert command: db.student.insert({ name: "Viraj" }) Above command will create a collection named student if it doesn't exist already in the database. But we can explicitly create a collection using the createCollection() command. The syntax of createCollection method is: db.createCollection(name, options) In the above command, name will be the name of the collection and options is a document which can be used to specify configurations for the collection. options parameter is optional, and you can simply create a collection by just providing a name for the collection. But if you want to configure your collection, you can use various options available to do so. Following are the available configuration options for creating a collection in MongoDB : Field Type Description capped boolean (Optional) To create a capped collection, where in we specify the maximum size or document counts to prevent it from growing beyond a set maximum value. size number (Optional) To specify the maximum size in bytes for a capped collection. If a collection is capped and reaches its maximum size limit, MongoDB then removes older documents from it to make space for new. max number (Optional) This can be used to specify the maximum number of documents allowed in a capped collection. validator document (Optional) Validates any document inserted or updated against provided validation rules.
  • 20. MongoDB Database pg. 19 validationLevel string (Optional) This is used to define how strictly validation rules must be applied to existing documents during an update. Available values are: off No validation for inserts or updates. strict This is the default value for this option. This instructs MongoDB to apply validation rules to all inserts and updates. moderate This is used when we want to apply validation rules to inserts and updates on only the existing valid documents and not on the existing invalid documents. validationAction string (Optional) This can be used to set the action to be taken upon validation i.e. if any document fails the set validation then whether to show error or just warn about the violations. Default value is error. Creating a Capped Collection We can create a capped collection using the following command. db.createCollection("student", { capped : true, size : 5242880, max : 5000 } ) This will create a collection named student, with maximum size of 5 megabytes and maximum of 5000 documents. Drop a Collection Any collection in a database in MongoDB can be dropped easily using the following command: db.collection_name.drop() drop() method will return true is the collection is dropped successfully, else it will return false.
  • 21. MongoDB Database pg. 20 CURD OPERATIONS CRUD Operationsin MongoDB CRUD operations refer to the basic Insert, Read, Update and Delete operations. In the previous chapter, we learnt about how to create a database and drop the database in MongoDB. Now, let us learn how to perform CRUD (Create/Read/Update/Delete) operations in MongoDB.
 Inserting a document into a collection (Create) The command db.collection.insert() will perform an insert operation into a collection of a document. Let us insert a document to a student collection. You must be connected to a database for doing any insert. It is done as follows: db.student.insert({ regNo: "3014", name: "Test Student", course: { courseName: "MCA", duration: "3 Years" }, address: { city: "Bangalore", state: "KA", country: "India" } })
  • 22. MongoDB Database pg. 21 Note: that an entry has been made into the collection called student. Querying a document from a collection (Read) To retrieve (Select) the inserted document, run the below command. The find() command will retrieve all the documents of the given collection. db.collection_name.find() NOTE: Please observe that the record retrieved contains an attribute called _id with some unique identifier value called ObjectId which acts as a document identifier. If a record is to be retrieved based on some criteria, the find() method should be called passing parameters, then the record will be retrieved based on the attributes specified. db.collection_name.find({"fieldname":"value"})
  • 23. MongoDB Database pg. 22 For Example: Let us retrieve the record from the student collection where the attribute regNo is 3014and the query for the same is as shown below: db.students.find({"regNo":"3014"}) Updating a document in a collection (Update) In order to update specific field values of a collection in MongoDB, run the below query. db.collection_name.update() update() method specified above will take the fieldname and the new value as argument to update a document. Let us update the attribute name of the collection student for the document with regNo 3014. db.student.update({ "regNo": "3014" }, $set: { "name":"Viraj" }) You will see the following in the Command Prompt:
  • 24. MongoDB Database pg. 23 Removing an entry from the collection (Delete) Let us now look into the deleting an entry from a collection. In order to delete an entry from a collection, run the command as shown below: db.collection_name.remove({"fieldname":"value"}) For Example: db.student.remove({"regNo":"3014"}) Note that after running the remove() method, the entry has been deleted from the student collection.
  • 25. MongoDB Database pg. 24 CONNECTIVITY Java MongoDB Connectivity To connect with MongoDB database, Java project includes the following steps. Here, we are creating a maven project and providing dependency for the mongodb-driver. Follow the Steps: 1) Create a Maven Project 2) Add Dependency to POM file // pom.xml 1. <? xml version="1.0" encoding="UTF-8"?> 2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/200 1/XMLSchema- instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.o rg/xsd/maven-4.0.0.xsd"> 3. <modelVersion>4.0.0</modelVersion> 4. <groupId>com.javatpoint</groupId> 5. <artifactId>java-mongo-db</artifactId> 6. <version>1.0-SNAPSHOT</version> 7. <packaging>jar</packaging> 8. <properties> 9. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 10. <maven.compiler.source>1.8</maven.compiler.source> 11. <maven.compiler.target>1.8</maven.compiler.target> 12. </properties> 13. <name>java-mongodb</name> 14. <dependencies>
  • 26. MongoDB Database pg. 25 15. <dependency> 16. <groupId>org.mongodb</groupId> 17. <artifactId>mongodb-driver</artifactId> 18. <version>3.4.2</version> 19. </dependency> 20. </dependencies> 21. </project> 3) Create Java File Create a Java file and write code to create connection. // JavaMongoDemo.java 1. package com.javatpoint.java.mongo.db; 2. import com.mongodb.MongoClient; 3. import com.mongodb.client.MongoCollection; 4. import com.mongodb.client.MongoDatabase; 5. import org.bson.Document; 6. public class JavaMongoDemo { 7. public static void main(String[] args){ 8. try{ 9. //---------- Connecting DataBase -------------------------// 10. MongoClient mongoClient = new MongoClient( "localhost" , 27017 ); 11. //---------- Creating DataBase ---------------------------// 12. MongoDatabase db = mongoClient.getDatabase("javatpoint"); 13. //---------- Creating Collection -------------------------// 14. MongoCollection<Document> table = db.getCollection("employee"); 15. //---------- Creating Document ---------------------------// 16. Document doc = new Document("name", "Peter John"); 17. doc.append("id",12); 18. //----------- Inserting Data ------------------------------// 19. table.insertOne(doc); 20. }catch(Exception e){ 21. System.out.println(e); 22. } 23. } 24. }
  • 27. MongoDB Database pg. 26 4) Build Dependency to load JAR Project Structure Finally, our project structure look like this. 5) Enter into Mongo Shell Make sure, we have mongoDB installed. After installing, enter into mongo shell by typing the following command.
  • 28. MongoDB Database pg. 27 $ mongo Databases We can see available databases by using the following command. > show dbs We can see that there is no database available. let's create a database. Run Java File
  • 29. MongoDB Database pg. 28 Run this file to create database. Database Check MongoDB again to see the available databases. See, a database javatpoint is created. Collection See, the created collection employee. Record See the inserted record. Well, we can see that the Java program is executing fine and we can also perform other databases operations as well.