SlideShare a Scribd company logo
Introduction to MongoDB
What is MongoDB?
 Developed by 10gen
 Founded in 2007
 A document-oriented, NoSQL database
 Hash-based, schema-less database • No Data Definition Language
 In practice, this means you can store hashes with any keys and values that
you choose • Keys are a basic data type but in reality stored as strings
 Document Identifiers (_id) will be created for each document, field name
reserved by system
Cont..
 Application tracks the schema and mapping • Uses BSON format
 Based on JSON
 Written in C++
 Supports APIs (drivers) in many computer languages
 JavaScript, Python, Ruby, Perl, Java, Java Scala, C#, C++, Haskell, Erlang
Functionality of MongoDB
 Dynamic schema
 No DDL
 Document-based database
 Secondary indexes
 Query language via an API
 Atomic writes and fully-consistent reads
 If system configured that way
 Master-slave replication with automated failover (replica sets)
 Built-in horizontal scaling via automated range-based partitioning of data
(sharding)
 No joins nor transactions
Why use MongoDB?
 Simple queries
 Functionality provided applicable to most web applications
 Easy and fast integration of data
 No ERD diagram
 Not well suited for heavy and complex transactions systems
MongoDB: CAP approach
 Focus on Consistency and Partition tolerance
 Consistency
 all replicas contain the same version of the data
 Availability
 system remains operational on failing nodes • Partition tolarence
 multiple entry points
 system remains operational on system split
MongoDB: Hierarchical Objects
• A MongoDB instance may have zero or more ‘databases’
• A database may have zero or more ‘collections’.
• A collection may have zero or more ‘documents’.
• A document may have one or more ‘fields’.
• MongoDB ‘Indexes’ function much like their RDBMS counterparts.
MongoDB Processes and configuration
 Mongod – Database instance
 Mongos - Sharding processes
 Analogous to a database router.
 Processes all requests
 Decides how many and which mongodsshould receive the query
 Mongos collates the results, and sends it back to the client.
 Mongo – an interactive shell ( a client)
 Fully functional JavaScript environment for use with a MongoDB
 You can have one mongos for the whole system no matter how many
mongods you have
Choices made for Design of MongoDB
 Scale horizontally over commodity hardware
 Lots of relatively inexpensive servers
 Keep the functionality that works well in RDBMSs – Ad hoc queries –
Fully featured indexes – Secondary indexes
 What doesn’t distribute well in RDB?
– Long running multi-row transactions
– Joins
– Both artifacts of the relational data model (row x column)
BSON format
 Binary-encoded serialization of JSON-like documents
 Zero or more key/value pairs are stored as a single entity
 Each entry consists of a field name, a data type, and a value
 Large elements in a BSON document are prefixed with a length field to
facilitate scanning
JSON format
 Data is in name / value pairs
 A name/value pair consists of a field name followed by a colon, followed
by a value: • Example: “name”: “R2-D2”
 Data is separated by commas
Example: “name”: “R2-D2”, race : “Droid” • Curly braces hold
objects
Example: {“name”: “R2-D2”, race : “Droid”, affiliation: “rebels”}
 An array is stored in brackets []
Example [ {“name”: “R2-D2”, race : “Droid”, affiliation: “rebels”},
 {“name”: “Yoda”, affiliation: “rebels”} ]
MongoDB Features
• Document-Oriented storage
• Full Index Support
• Replication & High Availability
• Auto-Sharding
• Querying
• Fast In-Place Updates
• Map/Reduce functionality
Index Functionality
 B+ tree indexes
 An index is automatically created on the _id field (the
primary key)
 Users can create other indexes to improve query performance
or to enforce Unique values for a particular field
 Supports single field index as well as Compound index
 Like SQL order of the fields in a compound index matters
 If you index a field that holds an array value, MongoDB
creates separate index entries for every element of the array.
Cont..
• Sparse property of an index ensures that the index only contain entries for
documents that have the indexed field. (so ignore records that do not have
the field defined)
• If an index is both unique and sparse – then the system will reject records
that have a duplicate key value but allow records that do not have the
indexed field defined
CRUD operations
• Create
db.collection.insert( )
db.collection.save( )
db.collection.update( , , { upsert: true } )
• Read
db.collection.find( , )
db.collection.findOne( , )
• Update
db.collection.update( , , )
• Delete
db.collection.remove( , )
Aggregated functionality
 Aggregation framework provides SQL-like aggregation functionality
 Pipeline documents from a collection pass through an aggregation
pipeline, which transforms these objects as they pass through
 Expressions produce output documents based on calculations performed on
input documents
 Example db.parts.aggregate ( {$group : {_id: type, totalquantity : { $sum:
quanity} } } )
Map reduce functionality
 Performs complex aggregator functions given a collection of keys, value
pairs
 Must provide at least a map function, reduction function and a name of the
result set
 db.collection.mapReduce( , , { out: , query: , sort: , limit: , finalize: , scope:
, jsMode: , verbose: } )
Indexes: High performance read
 Typically used for frequently used queries
 Necessary when the total size of the documents exceeds the amount of
available RAM.
 Defined on the collection level
 Can be defined on 1 or more fields
 Composite index (SQL) Compound index (MongoDB)

 B-tree index
 Only 1 index can be used by the query optimizer when retrieving data
Replication of data
 Ensures redundancy, backup, and automatic failover
 Recovery manager in the RDMS
 Replication occurs through groups of servers known as replica sets
 Primary set – set of servers that client tasks direct updates to
 Secondary set – set of servers used for duplication of data
Consistency of data
 All read operations issued to the primary of a replica set are consistent
with the last write operation
 Reads to a primary have strict consistency
 Reads reflect the latest changes to the data Reads to a secondary have
eventual consistency
 Updates propagate gradually

More Related Content

PPTX
MongoDB_ppt.pptx
PDF
2016 feb-23 pyugre-py_mongo
PDF
Using MongoDB and Python
PDF
Quick overview on mongo db
PPTX
MongoDbPpt based on python installation.
PDF
Mongodb Introduction
PPTX
MongoDB introduction features -presentation - 2.pptx
PPTX
mongo.pptx
MongoDB_ppt.pptx
2016 feb-23 pyugre-py_mongo
Using MongoDB and Python
Quick overview on mongo db
MongoDbPpt based on python installation.
Mongodb Introduction
MongoDB introduction features -presentation - 2.pptx
mongo.pptx

Similar to MongoDB is a document database. It stores data in a type of JSON format called BSON. (20)

PPTX
Mongo db
PPTX
Introduction to MongoDB
PPT
MongoDB Pros and Cons
PPT
9. Document Oriented Databases
PDF
MongoDB Interview Questions PDF By ScholarHat
PDF
MongoDB.pdf
PDF
MongoDB Interview Questions PDF By ScholarHat
PPTX
fard car.pptx
PDF
MongoDB NoSQL database a deep dive -MyWhitePaper
PPTX
PPTX
MongoDB-presentation.pptx
PPTX
UNIT-1 MongoDB.pptx
PDF
MongoDB - An Introduction
PPTX
MongoDB using Grails plugin by puneet behl
PPTX
Introduction to MongoDB.pptx
KEY
Seedhack MongoDB 2011
ODP
MongoDB - A Document NoSQL Database
PPTX
Query Optimization in MongoDB
PPTX
Mongo db Quick Guide
PPTX
Introduction to MongoDB – A NoSQL Database
Mongo db
Introduction to MongoDB
MongoDB Pros and Cons
9. Document Oriented Databases
MongoDB Interview Questions PDF By ScholarHat
MongoDB.pdf
MongoDB Interview Questions PDF By ScholarHat
fard car.pptx
MongoDB NoSQL database a deep dive -MyWhitePaper
MongoDB-presentation.pptx
UNIT-1 MongoDB.pptx
MongoDB - An Introduction
MongoDB using Grails plugin by puneet behl
Introduction to MongoDB.pptx
Seedhack MongoDB 2011
MongoDB - A Document NoSQL Database
Query Optimization in MongoDB
Mongo db Quick Guide
Introduction to MongoDB – A NoSQL Database
Ad

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Lesson notes of climatology university.
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Pre independence Education in Inndia.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Pharma ospi slides which help in ospi learning
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Sports Quiz easy sports quiz sports quiz
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O7-L3 Supply Chain Operations - ICLT Program
Supply Chain Operations Speaking Notes -ICLT Program
Lesson notes of climatology university.
PPH.pptx obstetrics and gynecology in nursing
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Types and Its function , kingdom of life
2.FourierTransform-ShortQuestionswithAnswers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pre independence Education in Inndia.pdf
VCE English Exam - Section C Student Revision Booklet
STATICS OF THE RIGID BODIES Hibbelers.pdf
Classroom Observation Tools for Teachers
Microbial disease of the cardiovascular and lymphatic systems
Pharma ospi slides which help in ospi learning
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Microbial diseases, their pathogenesis and prophylaxis
Ad

MongoDB is a document database. It stores data in a type of JSON format called BSON.

  • 2. What is MongoDB?  Developed by 10gen  Founded in 2007  A document-oriented, NoSQL database  Hash-based, schema-less database • No Data Definition Language  In practice, this means you can store hashes with any keys and values that you choose • Keys are a basic data type but in reality stored as strings  Document Identifiers (_id) will be created for each document, field name reserved by system
  • 3. Cont..  Application tracks the schema and mapping • Uses BSON format  Based on JSON  Written in C++  Supports APIs (drivers) in many computer languages  JavaScript, Python, Ruby, Perl, Java, Java Scala, C#, C++, Haskell, Erlang
  • 4. Functionality of MongoDB  Dynamic schema  No DDL  Document-based database  Secondary indexes  Query language via an API  Atomic writes and fully-consistent reads  If system configured that way  Master-slave replication with automated failover (replica sets)  Built-in horizontal scaling via automated range-based partitioning of data (sharding)  No joins nor transactions
  • 5. Why use MongoDB?  Simple queries  Functionality provided applicable to most web applications  Easy and fast integration of data  No ERD diagram  Not well suited for heavy and complex transactions systems
  • 6. MongoDB: CAP approach  Focus on Consistency and Partition tolerance  Consistency  all replicas contain the same version of the data  Availability  system remains operational on failing nodes • Partition tolarence  multiple entry points  system remains operational on system split
  • 7. MongoDB: Hierarchical Objects • A MongoDB instance may have zero or more ‘databases’ • A database may have zero or more ‘collections’. • A collection may have zero or more ‘documents’. • A document may have one or more ‘fields’. • MongoDB ‘Indexes’ function much like their RDBMS counterparts.
  • 8. MongoDB Processes and configuration  Mongod – Database instance  Mongos - Sharding processes  Analogous to a database router.  Processes all requests  Decides how many and which mongodsshould receive the query  Mongos collates the results, and sends it back to the client.  Mongo – an interactive shell ( a client)  Fully functional JavaScript environment for use with a MongoDB  You can have one mongos for the whole system no matter how many mongods you have
  • 9. Choices made for Design of MongoDB  Scale horizontally over commodity hardware  Lots of relatively inexpensive servers  Keep the functionality that works well in RDBMSs – Ad hoc queries – Fully featured indexes – Secondary indexes  What doesn’t distribute well in RDB? – Long running multi-row transactions – Joins – Both artifacts of the relational data model (row x column)
  • 10. BSON format  Binary-encoded serialization of JSON-like documents  Zero or more key/value pairs are stored as a single entity  Each entry consists of a field name, a data type, and a value  Large elements in a BSON document are prefixed with a length field to facilitate scanning
  • 11. JSON format  Data is in name / value pairs  A name/value pair consists of a field name followed by a colon, followed by a value: • Example: “name”: “R2-D2”  Data is separated by commas Example: “name”: “R2-D2”, race : “Droid” • Curly braces hold objects Example: {“name”: “R2-D2”, race : “Droid”, affiliation: “rebels”}  An array is stored in brackets [] Example [ {“name”: “R2-D2”, race : “Droid”, affiliation: “rebels”},  {“name”: “Yoda”, affiliation: “rebels”} ]
  • 12. MongoDB Features • Document-Oriented storage • Full Index Support • Replication & High Availability • Auto-Sharding • Querying • Fast In-Place Updates • Map/Reduce functionality
  • 13. Index Functionality  B+ tree indexes  An index is automatically created on the _id field (the primary key)  Users can create other indexes to improve query performance or to enforce Unique values for a particular field  Supports single field index as well as Compound index  Like SQL order of the fields in a compound index matters  If you index a field that holds an array value, MongoDB creates separate index entries for every element of the array.
  • 14. Cont.. • Sparse property of an index ensures that the index only contain entries for documents that have the indexed field. (so ignore records that do not have the field defined) • If an index is both unique and sparse – then the system will reject records that have a duplicate key value but allow records that do not have the indexed field defined
  • 15. CRUD operations • Create db.collection.insert( ) db.collection.save( ) db.collection.update( , , { upsert: true } ) • Read db.collection.find( , ) db.collection.findOne( , ) • Update db.collection.update( , , ) • Delete db.collection.remove( , )
  • 16. Aggregated functionality  Aggregation framework provides SQL-like aggregation functionality  Pipeline documents from a collection pass through an aggregation pipeline, which transforms these objects as they pass through  Expressions produce output documents based on calculations performed on input documents  Example db.parts.aggregate ( {$group : {_id: type, totalquantity : { $sum: quanity} } } )
  • 17. Map reduce functionality  Performs complex aggregator functions given a collection of keys, value pairs  Must provide at least a map function, reduction function and a name of the result set  db.collection.mapReduce( , , { out: , query: , sort: , limit: , finalize: , scope: , jsMode: , verbose: } )
  • 18. Indexes: High performance read  Typically used for frequently used queries  Necessary when the total size of the documents exceeds the amount of available RAM.  Defined on the collection level  Can be defined on 1 or more fields  Composite index (SQL) Compound index (MongoDB)   B-tree index  Only 1 index can be used by the query optimizer when retrieving data
  • 19. Replication of data  Ensures redundancy, backup, and automatic failover  Recovery manager in the RDMS  Replication occurs through groups of servers known as replica sets  Primary set – set of servers that client tasks direct updates to  Secondary set – set of servers used for duplication of data
  • 20. Consistency of data  All read operations issued to the primary of a replica set are consistent with the last write operation  Reads to a primary have strict consistency  Reads reflect the latest changes to the data Reads to a secondary have eventual consistency  Updates propagate gradually