MongoDb is a document oriented database and very flexible one as it gives horizontal scalability.
In this presentation basic study about mongodb with installation steps and basic commands are described.
2. Document Database
One of the most popular ways of storing data is a
document data model, where each record and its
associated data is thought of as a “document”.
In a document database, such as MongoDB, everything
related to a database object is encapsulated together.
3. Why use MongoDB?
• SQL was invented in the 70’s to store data.
But the environment for data, as well as
programming, has changed since the development
of the SQL database:
•The emergence of cloud computing has brought
deployment and storage costs down dramatically.
4. • The need to store unstructured data, such as social media
posts and multimedia, has grown rapidly.
• Agile development methods mean that the database
schema needs to change rapidly as demands evolve
6. • MongoDB stores documents (or) objects.
• Now-a-days, everyone works with objects
(Python/Ruby/Java/etc.)
• And we need Databases to persist our objects. Then why not
store objects directly ?
• Embedded documents and arrays reduce need for joins. No
Joins and No-multi document transactions.
7. What is MongoDB ?
MongoDb is a Scalable , High-Performance
Open-source, Schema-Free , Document-orientated
database.
9. High Performance
Focus on speed, performance, flexibility.
Not concerned with transactional stuff and relational
semantics
DBs should be an on-demand commodity, in a cloudlike
fashion
11. Document Oriented Database
Store all information for an object in a single instance.
• No spanning tables for all information
• No more normalization
#Each stored object can be different.
• Not all stord documents need to contain same data.
#handles semi structured,unstructured data.
12. RDBMS to MONGODB
DATABSE DATABASE
TABLE COLLECTION
TUPLE/ROW DOCUMENT
COLOUMN FIELD
PRIMARY KEY PRIMARY KEY (DEFAULT KEY _ID
PROVIDED BY MONGODB ITSELF)
13. Hitting RDBMS Limits
Data Types
•Unstructured data
•Semi-structured data
•Polymorphic data
Volume of Data
•Petabytes of data
•Trillions of records
•Millions of queries per
second
Agile Development
•Iterative
•Short development
cycles
•New workloads
New Architectures
•Horizontal scaling
•Commodity servers
•Cloud computing
14. RDBMS
The Power of Dynamic Schema
MongoDB
{
_id : ObjectId("4c4ba5e5e8aabf3"),
employee_name: "Dunham, Justin",
department : "Marketing",
title : "Product Manager, Web",
report_up: "Neray, Graham",
pay_band: “C",
benefits : [
{ type : "Health",
plan : "PPO Plus" },
{ type : "Dental",
plan : "Standard" }
]
}
15. Features
• Built for Speed
• Rich Document based queries for Easy
readability.
• Full Index Support for High Performance.
• Replication and Failover for High
Availability.
• Auto Sharding for Easy Scalability.
• Map / Reduce for Aggregation.
16. • The queries are written in document format
for easy readability and understanding.
• A database index is a data structure that
improves the speed of data retrieval
operations
17. REPLICATION
Process of synchronizing data across
multiple servers.
Provides redundancy and increases data
availability with multiple copies of data on
different database servers.
18. Why Replication
• Allows you to recover from hardware failure and
service interruptions
• Read scaling (extra copies to read from).
• High (24*7) availability of data.
• No downtime for maintenance (like backups,
index rebuilds, compaction)
19. How Replication Works in
MongoDB
MongoDB achieves replication by the use of replica set.
Replica set is a group of two or more nodes: Primary and
Secondary
All data replicates from primary to secondary
Client application always interacts with primary,
replicating the data on secondary.
20.
21. Sharding
Sharding is the process of storing data records
across multiple machines.
It is MongoDB's approach to meeting the demands
of data growth.
Sharding solves the problem of increased data size
with horizontal scaling.
22. Why Sharding over
Replication ?
1. Single replica set has limitation of 12 nodes.
2. Memory can't be large enough when active
dataset is big
3. Latency sensitive queries still go to master
4. Vertical scaling is too expensive
23.
24. MAP-REDUCE
1. MongoDB applies the map phase to each input
document.
2. For multiple key values, MongoDB applies
the reduce phase, which collects and condenses
the aggregated data.
3. It is same as Group By clause in sql but much
more efficient.
27. Some Cool features
• Geo-spatial Indexes for Geo-spatial queries.
$near, $within_distance, Bound queries (circle, box)
• GridFS
Stores Large Binary Files.
• Map/Reduce
GROUP BY in SQL, map/reduce in MongoDB.
29. Mongodb Installation
MongoDB is a document oriented database.
Which provides
High performance,
High availability
Easy scalability.
MongoDB works on concept of collection and document.
55. We created database (Movies) is not
present in list.
To display database, we need to insert at
least one document into it.
So to insert something in database we
have to use insert command
58. The Create collection method
Syntax
db.createCollection(name, options)
“name” is name of collcetion and
“options” is a document and is used to
specify configuration of collection.
(“options” parameter is optional so we
need only to give name)
63. The find and pretty method
SYNTAX
db.collection_name.find()
db.collection_name.find().pretty()
EXAMPLE
db.players.find()
db.players.find().pretty()
66. The query of documents
depends on some condition
Operation syntax example RDBMS
equivalence
Equality {<key>:<value>} Db.players.find({“c
ountry”:”Brazil”}).
pretty()
Where
country=‘Brazil
Less than {<key>:{$lt:<value
>}}
Db.players.find({“
Height”:{$lt:1.8}}.p
retty()
Where Height<1.9
Greater than {<key>:{$gt:<value
>}}
Db.players.find({“
Height”:{$gt:1.8}}.p
retty()
Where Height>1.8
Not equal {<key>:{$ne:<value
>}}
Db.players.find({“c
ountry”:{$ne:”Brazi
l”}}
Where
Country!=Brazil
69. If you want to update in multi documents then we can use
this command:
db.players.update({'Name':'Sergio
Ramos'},{$set:{'Name':'cavini'}}) ,{multi:true})