Mongodb Introductioninstalaltion and Basic Crud Operations
Mongodb Introductioninstalaltion and Basic Crud Operations
Introduction, Installation
& Execution
By Prof. B.A.Khivsara
Note: The material to prepare this presentation has been taken from internet and are
generated only for students reference and not for commercial use.
Outline
Difference Between SQL and NoSQL
Study of Open Source NOSQL
Database
MongoDB Installation,
Execution
Difference Between SQL and
NoSQL
• SQL Databases
March 2, 2025
• SQL Standard
• SQL Characteristics
• SQL Database Examples
• NoSQL Databases
• NoSQL Defintion
• General Characteristics
• NoSQL Database Types
• NoSQL Database Examples
3
SQL Characteristics
Data stored in tables
March 2, 2025
Relationships represented by data
Transactions
4
Abstraction from physical layer
Data Definition Language
Schema defined at the start
March 2, 2025
Create Table
Stored Modules
Alter …
Drop …
5
Security and Access Control
Data Manipulation Language (DML)
March 2, 2025
Data manipulated with Select, Insert, Update, & Delete
Data Aggregation
Compound statements
March 2, 2025
(commit) or none of it completes
March 2, 2025
• IBM DB2
• Oracle RDMS
• Microsoft SQL Server
• Sybase SQL Anywhere
• Open Source (with commercial options)
• MySQL
• Ingres
Significant portions of the
world’s economy use SQL databases!
8
NoSQL Definition- From www.nosql-database.org
Next Generation Databases mostly addressing some of the
March 2, 2025
points:
• non-relational,
• distributed,
• open-source and
• horizontal scalable.
March 2, 2025
• Cassandra
• CouchDB
• Hadoop & Hbase
• MongoDB
• StupidDB
• Etc.
10
NoSQL Distinguishing Characteristics
Large data volumes
• Google’s “big data”
March 2, 2025
Scalable replication and distribution
• Potentially thousands of machines
• Potentially distributed around the world
Schema-less
CAP Theorem 11
March 2, 2025
• Basically Available,
• Soft state,
• Eventually Consistent
• Characteristics
• Weak consistency – stale data OK
• Availability first
• Best effort
• Approximate answers OK
• Aggressive (optimistic)
• Simpler and faster
12
Brewer’s CAP Theorem
March 2, 2025
CAP
Theorem
Partition
Consistency Availability
tolerance
13
Consistency
• all nodes see the same data at the same time – Wikipedia
March 2, 2025
• client perceives that a set of operations has occurred all at
once – Pritchett
• More like Atomic in ACID transaction properties
14
Availability
• node failures do not prevent survivors
March 2, 2025
from continuing to operate – Wikipedia
• Every operation must terminate in an intended response –
Pritchett
15
Partition Tolerance
• the system continues to operate despite
March 2, 2025
arbitrary message loss – Wikipedia
• Operations will complete, even if individual components are
unavailable – Pritchett
16
Outline
Difference Between SQL and NoSQL
Study of Open Source NOSQL
Database
MongoDB Installation,
Execution
Open Source
March 2, 2025
Small upfront software costs
March 2, 2025
Column Store –
Each storage block
contains data from
only one column
Document Store
Key-Value Store – stores
– Hash table of documents
keys made up of
tagged elements 19
Other Non-SQL Databases
• XML Databases
March 2, 2025
• Graph Databases
• Codasyl Databases
• Object Oriented Databases
• Etc…
20
NoSQL Example: Column Store
Each storage block contains data from only one
March 2, 2025
column
Example: Hadoop/Hbase
• http://hadoop.apache.org/
• Yahoo, Facebook
March 2, 2025
• Multiple row/record/documents are inserted at the same time so
updates of column blocks can be aggregated
• Retrievals access only some of the columns in a
row/record/document
22
NoSQL Examples: Key-Value Store
• Hash tables of Keys
March 2, 2025
• Values stored with Keys
• Fast access to small data values
• Example – Project-Voldemort
• http://www.project-voldemort.com/
• Linkedin
• Example – MemCacheDB
• http://memcachedb.org/
• Backend storage is Berkeley-DB
23
Map Reduce
• Technique for indexing and searching large data volumes
March 2, 2025
• Two Phases, Map and Reduce
• Map
• Extract sets of Key-Value pairs from underlying data
• Potentially in Parallel on multiple machines
• Reduce
• Merge and sort sets of Key-Value pairs
• Results may be useful for other searches
24
Map Reduce Patent
Google granted US Patent 7,650,331, January 2010
March 2, 2025
System and method for efficient large-scale data processing
Example: CouchDB
March 2, 2025
• http://couchdb.apache.org/
• BBC
Example: MongoDB
• http://www.mongodb.org/
• Foursquare, Shutterfly
March 2, 2025
"_rev": "314159",
"type": "abstract",
March 2, 2025
• GUID – Global Unique Identifier
• Passed in or generated by CouchDB
• "_rev"
• Revision number
• Versioning mechanism
• "type", "author", "title", etc.
• Arbitrary tags
• Schema-less
• Could be validated after the fact by user-written routine
28
MongoDB
What is MongoDB ?
• Scalable High-Performance Open-source,
Document-orientated database.
•Web
Caching
2.0,and High SAAS,
Media, Scalability
Gaming
HealthCare, Finance, Telecom, Government
Not great for?
• Highly Transactional Applications.
No complex joins
35
JSON
“JavaScript Object Notation”
Built on
• name/value pairs
• Ordered list of values
http://json.org/
BSON
“Binary JSON”
Goals
• Lightweight
• Traversable
• Efficient (decoding and encoding)
http://bsonspec.org/
BSON Example
{
"_id" : "37010"
“City" : “Nashik",
“Pin" : 423201,
"state" : “MH",
“Postman” : {
name: “Ramesh Jadhav”
address: “Panchavati”
}
}
Data Types of MongoDB
Integer
Date Boolean
Object ID String
Null Arrays
Data Types
• String : This is most commonly used datatype to store the data. String in
mongodb must be UTF-8 valid.
• Integer : This type is used to store a numerical value. Integer can be 32 bit
or 64 bit depending upon your server.
• Boolean : This type is used to store a boolean (true/ false) value.
• Double : This type is used to store floating point values.
• Min/ Max keys : This type is used to compare a value against the lowest
and highest BSON elements.
• Arrays : This type is used to store arrays or list or multiple values into one
key.
• Timestamp : ctimestamp. This can be handy for recording when a
document has been modified or added.
• Object : This datatype is used for embedded documents.
Data Types
• Null : This type is used to store a Null value.
• Symbol : This datatype is used identically to a string however, it's
generally reserved for languages that use a specific symbol type.
• Date : This datatype is used to store the current date or time in
UNIX time format. You can specify your own date time by creating
object of Date and passing day, month, year into it.
• Object ID : This datatype is used to store the document’s ID.
• Binary data : This datatype is used to store binay data.
• Code : This datatype is used to store javascript code into
document.
• Regular expression : This datatype is used to store regular
expression
Outline
Difference Between SQL and NoSQL
Study of Open Source NOSQL
Database
MongoDB Installation,
Execution
Find version of Windows
enter the following commands in the
Command Prompt or Powershell:
Open terminal
Execution
Basic Database Operations
Database
collection
Basic Database Operations- Database
use <database • switched to database provided with
name> ciommand
Find
Update
Delete
References
• https://docs.mongodb.com/manual/introduction/
• http://
metadata-standards.org/Document-library/Documents-by-nu
mber/WG2-N1501-N1550/WG2_N1537_SQL_Standard_and_
NoSQL_Databases%202011-05.ppt
• https://
www.slideshare.net/raviteja2007/introduction-to-mongodb-1
2246792
• https://docs.mongodb.com/manual/core/databases-and-colle
ctions
/
• https://docs.mongodb.com/manual/crud/