KEMBAR78
Mongodb Introduction | PPTX
Introduction to Mongo DB
(NO SQL data Base)
PREPARED BY: NABEEL RAZA
Overview
 What is NO SQL Data base?
 Types of NO SQL Data base.
 What is Mongo DB?
 RDBMs vs MongoDB
 Why Mongo DB?
 Limitation of MongoDB
 Mongo DB Architecture.
 Document (JSON) Structure.
 MongoDB environment setup
 Different Methods.
 Demo
 When to use Mongo DB?
What is No SQL data base
 It’s Not No SQL it’s NOT ONLY SQL.
 NoSQL is a non-relational DBMS, that does not require a fixed schema,
avoids joins, and is easy to scale.
 It’s not even a replacement to RDBMS.
 NoSQL databases are increasingly used in big data and real-time web
applications.
 For example, companies like Twitter, Facebook, Google that collect
terabytes of user data every single day.
Types of No SQl data base
 Key Value pair
Dynamo DB
Azure Table Storage (ATS )
 Graph database
 Document Based
Mango Db
AmazonSimple DB
Couch DB
 Column Oriented database
(#key,#value)
(Name, Tom)
(Age,25)
(Role, Student)
(University, CU)
[
{
"Name": "Tom",
"Age": 30,
"Role": "Student",
"University":
"CU",
}
]
Student
Tom
CU
25
Masters
Ottawa Location
• Neo4j
• Infogrid
Row Id Columns
1
Name Tom
Age 25
Role Student
Bigtable(Google)
HBase
What is Mongo DB
 MongoDB is a cross-platform, document oriented database that provides
 High performance.
 High availability.
 Easy scalability.
 MongoDB uses JSON-like documents with schema.
 MongoDB works on concept of collection and document.
 Developed by: MongoDB Inc.
RDBMS vs MongoDB
Why Mongo DB?
 All the modern applications deals with huge data.
 Development with ease is possible with mongo DB.
 Flexibility in deployment.
 Older database systems may not be compatible with the design.
And it’s a document oriented storage:- Data is stored in the form of
JSON Style.
Who are Using MongoDB?
 A survey by Siftery on MongoDB, there are around 4000+ company confirmed
that they are using MongoDB as Database. Some of the key names are :
• Castlight Health
• IBM
• Citrix
• Twitter
• T-Mobile
• Zendesk
• Sony
• BrightRoll
• Foursquare
• HTC
• InVision
• Intercom etc.
Limitation of MongoDB
 Nothing is fully complete or perfect.
 Joins not Supported( Joins functionality by adding by coding it manually)
 High Memory Usage.
 Limited Data Size(document size, not more than 16MB.)
 Limited Nesting(cannot perform nesting of documents for more than 100
levels.)
Mongo DB architecture
Mongo DB architecture
Architecture : -
Database
ContainerDocument
Document(JSON) structure
 The document has simple structure and very easy to
understand the content
 JSON is smaller, faster and lightweight compared to XML.
 For data delivery between servers and browsers, JSON is a
better choice
 Easy in parsing, processing, validating in all languages
 JSON can be mapped more easily into object oriented
system.
 [
 {
 "Name": "Tom",
 "Age": 30,
 "Role": "Student",
 "University": "CU",
}
{
 "Name": “Sam",
 "Age": 32,
 "Role": "Student",
 "University": “OU",
}
]
Difference Between XML And JSON
XML JSON
It is a markup language. It is a way of representing objects.
This is more verbose than JSON. This format uses less words.
It is used to describe the structured data. It is used to describe unstructured data
which include arrays.
Example:
<car>
<company>Volkswagen</company>
<name>Vento</name>
<price>800000</price> </car>
{
"company": Volkswagen,
"name": "Vento",
"price": 800000
}
MongoDB Environment Setup
 Know your Windows architecture
 Download MongoDB setup file
 Install MongoDB setup
 Set up MongoDB Environment
 Connect to the MongoDB server
 MongoDB as a Windows service
 Create configuration file
 Run MongoDB Environment setup
Know your Windows Architecture
 You must know which Windows version you are using.
 To know about your system architecture, open the command prompt and
execute some commands given below.
 Command: wmic os get osarchitecture.
 Download the MongoDB setup accordingly.
Download MongoDB Setup File
 Download the latest version of MongoDB from the official website.
 Link: ttps://www.mongodb.org/downloads
 Download the MSI file from this server.
 And install mongodb setup.
 There is an option to install MongoDB Compass too.
MongoDB Environment Setup
 MongoDB stored data in a specified directory.
 Create it manually in the MongoDB Folder on the C drive.
 Run the command in Command Prompt.(md datadb)
Start MongoDB
 To start mongodb server, we need to run the specific file.
Contd….
Connect to MongoDB Server
 After executing the MongoDB.exe file, Now we need to connect it to the
MongoDB server.
 We will connect it through Mongo.exe shell by opening another
command prompt.
MongoDB as a Windows Service
 Create some directories using command prompt & executing the following
commands:
 mkdir c:datadb
 mkdir c:datalog
 All of your database and the log files will be stored in these two folders.
MongoDB Document Structure
 There are TWO types of documents
 Referenced Documents
 Embedded Documents
Referenced Document
 Store the relationship between data by including links from one data to
another.
Embedded Documents
 Embedded documents create relationships between data by storing
related data in a single document structure.
MongoDB with Kafka
Demo
Some commonly used
Commands
 Use Command: to use the database.
 DB Command: to check selected DB
 Show dbs: list all databases
 dropDatabase: to drop selected db
 Example: -
• Use database_name;
• Db;
• Show dbs;
• dropDatabase()
The createCollection()
Method
 First we create database
 As we know there are table(s) in a
database
 And tables are know as documents
 First create Collection using command
“db. createCollection(name,option)”
 Example: -
Db.createCollection(“myTable”)
The insert() Method
 To insert data into MongoDB collection, you
need to use
MongoDB's insert() or save() method.
 The basic syntax of insert() command is as
follows −
“db.COLLECTION_NAME.insert(document)”
 Example: -
db.StudentRecord.insert (
{
"Name": "Tom",
"Age": 30,
"Role": "Student",
"University": "CU",
},
{
"Name": “Sam",
"Age": 22,
"Role": "Student",
"University": “OU",
}
)
The find() Method
 To query data from MongoDB collection, you need
to use MongoDB's find() method.
 The basic syntax of find() method is as follows −
“db.COLLECTION_NAME.find()”
 find() method will display all the documents in a
non-structured way.
 To display the results in a formatted way, you can
use pretty() method.
“db.mycol.find().pretty() “
 Example: -
db.StudentRecord.find()
.pretty()
The update() Method
 As we know that database consists of
some Collection and each collection
have some documents.
 Update this document by adding some
more information.
 “db.collection_name.update(criteria,
update_data )”
db.studentRecord.update(
{
"Name":"Tom",
"Age":30},
{
$set: {
"Name":"Tommy“,
"Age":35
}
}
}
)
The remove() Method
 MongoDB's remove() method is used to
remove a document from the collection.
remove() method accepts two parameters.
One is deletion criteria and second is
justOne flag.
 deletion criteria − (Optional) deletion
criteria according to documents will be
removed.
 justOne − (Optional) if set to true or 1, then
remove only one document.
 Syntax
 db.COLLECTION_NAME.remove(DELLETI
ON_CRITTERIA)
Remove based on
DELETION_CRITERIA
db.StudentRecord.remove({"Name":
"Tommy})
Remove Only One:-Removes first
record
db.StudentRecord.remove(DELETION
_CRITERIA,1)
Remove all Records
db.StudentRecord.remove()
When to use Mongo Db?
When your requirements has these properties :
 You absolutely must store unstructured data.
 Things coming from 3rd-party API you don’t control.
 Logs whose format may change any minute.
 You change your schema very often on a large dataset.
Mongodb Introduction

Mongodb Introduction

  • 1.
    Introduction to MongoDB (NO SQL data Base) PREPARED BY: NABEEL RAZA
  • 2.
    Overview  What isNO SQL Data base?  Types of NO SQL Data base.  What is Mongo DB?  RDBMs vs MongoDB  Why Mongo DB?  Limitation of MongoDB  Mongo DB Architecture.  Document (JSON) Structure.  MongoDB environment setup  Different Methods.  Demo  When to use Mongo DB?
  • 3.
    What is NoSQL data base  It’s Not No SQL it’s NOT ONLY SQL.  NoSQL is a non-relational DBMS, that does not require a fixed schema, avoids joins, and is easy to scale.  It’s not even a replacement to RDBMS.  NoSQL databases are increasingly used in big data and real-time web applications.  For example, companies like Twitter, Facebook, Google that collect terabytes of user data every single day.
  • 4.
    Types of NoSQl data base  Key Value pair Dynamo DB Azure Table Storage (ATS )  Graph database  Document Based Mango Db AmazonSimple DB Couch DB  Column Oriented database (#key,#value) (Name, Tom) (Age,25) (Role, Student) (University, CU) [ { "Name": "Tom", "Age": 30, "Role": "Student", "University": "CU", } ] Student Tom CU 25 Masters Ottawa Location • Neo4j • Infogrid Row Id Columns 1 Name Tom Age 25 Role Student Bigtable(Google) HBase
  • 5.
    What is MongoDB  MongoDB is a cross-platform, document oriented database that provides  High performance.  High availability.  Easy scalability.  MongoDB uses JSON-like documents with schema.  MongoDB works on concept of collection and document.  Developed by: MongoDB Inc.
  • 6.
  • 7.
    Why Mongo DB? All the modern applications deals with huge data.  Development with ease is possible with mongo DB.  Flexibility in deployment.  Older database systems may not be compatible with the design. And it’s a document oriented storage:- Data is stored in the form of JSON Style.
  • 8.
    Who are UsingMongoDB?  A survey by Siftery on MongoDB, there are around 4000+ company confirmed that they are using MongoDB as Database. Some of the key names are : • Castlight Health • IBM • Citrix • Twitter • T-Mobile • Zendesk • Sony • BrightRoll • Foursquare • HTC • InVision • Intercom etc.
  • 9.
    Limitation of MongoDB Nothing is fully complete or perfect.  Joins not Supported( Joins functionality by adding by coding it manually)  High Memory Usage.  Limited Data Size(document size, not more than 16MB.)  Limited Nesting(cannot perform nesting of documents for more than 100 levels.)
  • 10.
  • 11.
    Mongo DB architecture Architecture: - Database ContainerDocument
  • 12.
    Document(JSON) structure  Thedocument has simple structure and very easy to understand the content  JSON is smaller, faster and lightweight compared to XML.  For data delivery between servers and browsers, JSON is a better choice  Easy in parsing, processing, validating in all languages  JSON can be mapped more easily into object oriented system.  [  {  "Name": "Tom",  "Age": 30,  "Role": "Student",  "University": "CU", } {  "Name": “Sam",  "Age": 32,  "Role": "Student",  "University": “OU", } ]
  • 13.
    Difference Between XMLAnd JSON XML JSON It is a markup language. It is a way of representing objects. This is more verbose than JSON. This format uses less words. It is used to describe the structured data. It is used to describe unstructured data which include arrays. Example: <car> <company>Volkswagen</company> <name>Vento</name> <price>800000</price> </car> { "company": Volkswagen, "name": "Vento", "price": 800000 }
  • 14.
    MongoDB Environment Setup Know your Windows architecture  Download MongoDB setup file  Install MongoDB setup  Set up MongoDB Environment  Connect to the MongoDB server  MongoDB as a Windows service  Create configuration file  Run MongoDB Environment setup
  • 15.
    Know your WindowsArchitecture  You must know which Windows version you are using.  To know about your system architecture, open the command prompt and execute some commands given below.  Command: wmic os get osarchitecture.  Download the MongoDB setup accordingly.
  • 16.
    Download MongoDB SetupFile  Download the latest version of MongoDB from the official website.  Link: ttps://www.mongodb.org/downloads  Download the MSI file from this server.  And install mongodb setup.  There is an option to install MongoDB Compass too.
  • 17.
    MongoDB Environment Setup MongoDB stored data in a specified directory.  Create it manually in the MongoDB Folder on the C drive.  Run the command in Command Prompt.(md datadb)
  • 18.
    Start MongoDB  Tostart mongodb server, we need to run the specific file.
  • 19.
  • 20.
    Connect to MongoDBServer  After executing the MongoDB.exe file, Now we need to connect it to the MongoDB server.  We will connect it through Mongo.exe shell by opening another command prompt.
  • 21.
    MongoDB as aWindows Service  Create some directories using command prompt & executing the following commands:  mkdir c:datadb  mkdir c:datalog  All of your database and the log files will be stored in these two folders.
  • 22.
    MongoDB Document Structure There are TWO types of documents  Referenced Documents  Embedded Documents
  • 23.
    Referenced Document  Storethe relationship between data by including links from one data to another.
  • 24.
    Embedded Documents  Embeddeddocuments create relationships between data by storing related data in a single document structure.
  • 25.
  • 26.
  • 27.
    Some commonly used Commands Use Command: to use the database.  DB Command: to check selected DB  Show dbs: list all databases  dropDatabase: to drop selected db  Example: - • Use database_name; • Db; • Show dbs; • dropDatabase()
  • 28.
    The createCollection() Method  Firstwe create database  As we know there are table(s) in a database  And tables are know as documents  First create Collection using command “db. createCollection(name,option)”  Example: - Db.createCollection(“myTable”)
  • 29.
    The insert() Method To insert data into MongoDB collection, you need to use MongoDB's insert() or save() method.  The basic syntax of insert() command is as follows − “db.COLLECTION_NAME.insert(document)”  Example: - db.StudentRecord.insert ( { "Name": "Tom", "Age": 30, "Role": "Student", "University": "CU", }, { "Name": “Sam", "Age": 22, "Role": "Student", "University": “OU", } )
  • 30.
    The find() Method To query data from MongoDB collection, you need to use MongoDB's find() method.  The basic syntax of find() method is as follows − “db.COLLECTION_NAME.find()”  find() method will display all the documents in a non-structured way.  To display the results in a formatted way, you can use pretty() method. “db.mycol.find().pretty() “  Example: - db.StudentRecord.find() .pretty()
  • 31.
    The update() Method As we know that database consists of some Collection and each collection have some documents.  Update this document by adding some more information.  “db.collection_name.update(criteria, update_data )” db.studentRecord.update( { "Name":"Tom", "Age":30}, { $set: { "Name":"Tommy“, "Age":35 } } } )
  • 32.
    The remove() Method MongoDB's remove() method is used to remove a document from the collection. remove() method accepts two parameters. One is deletion criteria and second is justOne flag.  deletion criteria − (Optional) deletion criteria according to documents will be removed.  justOne − (Optional) if set to true or 1, then remove only one document.  Syntax  db.COLLECTION_NAME.remove(DELLETI ON_CRITTERIA) Remove based on DELETION_CRITERIA db.StudentRecord.remove({"Name": "Tommy}) Remove Only One:-Removes first record db.StudentRecord.remove(DELETION _CRITERIA,1) Remove all Records db.StudentRecord.remove()
  • 33.
    When to useMongo Db? When your requirements has these properties :  You absolutely must store unstructured data.  Things coming from 3rd-party API you don’t control.  Logs whose format may change any minute.  You change your schema very often on a large dataset.

Editor's Notes

  • #6 Ad-hoc Queries Schema-Less Database Document-Oriented Indexing Replication Aggregation GridFS Sharding High Performance
  • #8 Flexible database – Sharding(1-3) - High Speed - Ad-hoc Query Support -
  • #10 Joins:  But it may slow execution and affect performance. Memory: due to no functionality of joins, there is data redundancy. This results in increasing unnecessary usage of memory.
  • #17 MongoDB Compass is the GUI for MongoDB. Compass allows you to analyze and understand the contents of your data without formal knowledge of MongoDB query syntax.
  • #29 >db.createCollection(“mongodb”, { capped:true, size:1000000, max:2})