SlideShare a Scribd company logo
MongoDB
Tech Gupshup
In This Talk…
• What is MongoDB?
• Why use it?
• Documents and Collections
• Querying
• JavaScript Shell
• Schema Design
What is MongoDB?
Not a RDBMS
• Mongo is not a relational database like MySQL
• No transactions
• No referential integrity
• No joins
• No schema, so no columns or rows
• NoSQL
Not a Key-Value Store
• Mongo is not simply a key-value store like
Redis
• Stores structured data
• Indexes
• Map/Reduce
• Sharding, GridFS, etc.
Document-oriented Database
• Records are JSON documents (actually BSON)
• Stored in collections
• No predefined schema
• Docs in the same collection don’t even need to
have the same fields
• Operators for updates
–$set, $inc, $push, $pop, etc.
Mongo Document
• user = {
• name: "Frank Furter",
• occupation: "A scientist",
• location: "Transylvania"
• }
Why Use MongoDB?
• Organizations of all sizes are adopting
MongoDB because it enables them to build
applications faster, handle highly diverse data
types, and manage applications more
efficiently at scale.
• MongoDB’s flexible data model also means
that your database schema can evolve with
business requirements.
It’s Web Scale!
• Sharding built-in, automatic - As your
deployments grow in terms of data volume and
throughput, MongoDB scales easily with no
downtime, and without changing your
application. In contrast, to achieve scale with
MySQL often requires significant, custom
engineering work.
• Asynchronous replication for failover and
redundancy
It’s Pretty Painless
• Schemaless
– No more configuring database columns with types
– No more defining and managing migrations
– Just stick your data in there, it’s fine
• NoSQL
– Mongo’s query language is basically JSON
– The Mongo driver for your favorite language is
really nice and officially supported
– Handy JavaScript shell for the CLI
It’s Pretty Painless
/* First go create the database, the table, the schema, etc. */
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$sql = "INSERT INTO users (name, age) VALUES ('Janet', 23)";
mysql_query($sql);
$result = mysql_query("SELECT * FROM users WHERE age = 23");
$row = mysql_fetch_assoc($result);
echo "Oh, " . $row['name'] . "!"; // prints "Oh, Janet!"
$mongo = new Mongo(); // defaults to localhost with no auth
$users = $mongo->test_db->users; // database and collection created implicitly
$users->insert( array('name' => 'Brad', 'age' => 25) );
$user = $users->findOne( array('age' => 25) );
echo "Oh, " . $user->name . "!"; // prints "Oh, Brad!"
Documents and
Collections
Documents and Collections
• Documents are the records
– Like objects in OOP, or rows in RDBMS
• Collections are groups of documents
– Usually represent a top-level class in your app
– Unlike RDBMS tables, no predefined schema
• No foreign keys, so how do we reference other
objects?
– Don't! Just embed the sub-item in the parent doc
– Or, use a key for references and deal with the fact that you
don't get integrity or joins
Embedded Objects
• Documents can embed other documents
– Used to efficiently represent a relation
• For example:
{
name: 'Brad Majors',
address:
{
street: 'Oak Terrace',
city: 'Denton'
}
}
Querying
Queries
• Queries are documents
• Query expression objects indicate a pattern to
match
– db.users.find( {last_name: 'Smith'} )
• Several query objects for advanced queries
– db.users.find( {age: {$gte: 23} } )
– db.users.find( {age: {$in: [23,25]} } )
Querying Embedded Objects
• Exact match an entire embedded object
– db.users.find( {address: {street: 'Oak Terrace', city: 'Denton'}} )
• Dot-notation for a partial match
– db.users.find( {"address.city": 'Denton'} )
JavaScript Shell
JS Shell
• Comes with MongoDB
• Launch it with 'mongo' on the command-line
Schema Design
• There is no predefined schema
• Your application creates an schema with the
objects it creates
• The schema is implicit in the queries your
application runs
Schema Design
• Use collections to represent the top-level
classes of your application
• But don't just make a collection for every
object type
– These aren't like tables in an RDBMS
• Less normalization, more embedding
Example
• A blog post has an author, some text, and
many comments
• The comments are unique per post, but one
author has many posts
• How would you design this in SQL?
• Let's look at how we might design it in Mongo
Bad Schema Design: References
• Collections for posts, authors, and comments
• References by manually created ID
post = {
id: 150,
author: 100,
text: 'This is a pretty awesome post.',
comments: [100, 105, 112]
}
author = {
id: 100,
name: 'Michael Arrington'
posts: [150]
}
comment = {
id: 105,
text: 'Whatever this sux.'
}
Better Schema Design: Embedding
• Collection for posts
• Embed comments, author name
post = {
author: 'Michael Arrington',
text: 'This is a pretty awesome post.',
comments: [
'Whatever this post sux.',
'I agree, lame!'
]
}
Benefits
• Embedded objects brought back in the same
query as parent object
– Only 1 trip to the DB server required
• Objects in the same collection are generally
stored contiguously on disk
Indexes
• Mongo supports indexes to greatly improve
query performance
Schema Design Limitations
• No referential integrity
• High degree of denormalization means
updating something in many places instead of
one
• Lack of predefined schema is a double-edged
sword
– Objects within a collection can be completely
inconsistent in their fields
Final Thoughts
Final Thoughts
• MongoDB is fast
• Very rapid development, open source
• Document model is simple but powerful
• Advanced features like map/reduce etc. are
very compelling
• Surprisingly great drivers for most languages
Questions?

More Related Content

PDF
Scala with mongodb
Knoldus Inc.
 
PPT
Scala with MongoDB
Abdhesh Kumar
 
PPTX
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Ayes Chinmay
 
PDF
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
Matias Cascallares
 
PPTX
Sql Server 2016 and JSON
Greg McMurray
 
PDF
Building your first app with mongo db
MongoDB
 
KEY
MongoDB hearts Django? (Django NYC)
Mike Dirolf
 
PPTX
Using Webservice in iOS
Mahboob Nur
 
Scala with mongodb
Knoldus Inc.
 
Scala with MongoDB
Abdhesh Kumar
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Ayes Chinmay
 
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
Matias Cascallares
 
Sql Server 2016 and JSON
Greg McMurray
 
Building your first app with mongo db
MongoDB
 
MongoDB hearts Django? (Django NYC)
Mike Dirolf
 
Using Webservice in iOS
Mahboob Nur
 

What's hot (20)

PPTX
jQuery - Web Engineering
adeel990
 
KEY
Introduction to MongoDB
Neil Henegan
 
PPT
Connecting to a REST API in iOS
gillygize
 
PDF
mobile in the cloud with diamonds. improved.
Oleg Shanyuk
 
PPT
Web Services with Objective-C
Juio Barros
 
PPTX
Ajax xml json
Andrii Siusko
 
PPTX
Java script objects
AbhishekMondal42
 
PDF
A SOLID Design in InterSystems ObjectScript
AnastasiaDyubaylo
 
PPTX
Velocity 101 in Cascade Server CMS, by Penny Harding
hannonhill
 
PPTX
Getting Started with jQuery
Akshay Mathur
 
PDF
CouchDB in The Room
Makoto Ohnami
 
PPTX
Mongo - an intermediate introduction
nklmish
 
KEY
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Alex Nguyen
 
PDF
Getting started with MongoDB and Scala - Open Source Bridge 2012
sullis
 
PPT
Building web applications with mongo db presentation
Murat Çakal
 
PPTX
Tips for writing Javascript for Drupal
Sergey Semashko
 
PDF
Difference between xml and json
Umar Ali
 
PDF
Learn Learn how to build your mobile back-end with MongoDB
Marakana Inc.
 
PDF
Elastic Search
Lukas Vlcek
 
jQuery - Web Engineering
adeel990
 
Introduction to MongoDB
Neil Henegan
 
Connecting to a REST API in iOS
gillygize
 
mobile in the cloud with diamonds. improved.
Oleg Shanyuk
 
Web Services with Objective-C
Juio Barros
 
Ajax xml json
Andrii Siusko
 
Java script objects
AbhishekMondal42
 
A SOLID Design in InterSystems ObjectScript
AnastasiaDyubaylo
 
Velocity 101 in Cascade Server CMS, by Penny Harding
hannonhill
 
Getting Started with jQuery
Akshay Mathur
 
CouchDB in The Room
Makoto Ohnami
 
Mongo - an intermediate introduction
nklmish
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Alex Nguyen
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
sullis
 
Building web applications with mongo db presentation
Murat Çakal
 
Tips for writing Javascript for Drupal
Sergey Semashko
 
Difference between xml and json
Umar Ali
 
Learn Learn how to build your mobile back-end with MongoDB
Marakana Inc.
 
Elastic Search
Lukas Vlcek
 
Ad

Similar to Tech Gupshup Meetup On MongoDB - 24/06/2016 (20)

PPTX
Intro To Mongo Db
chriskite
 
PPTX
Mongo db
Gyanendra Yadav
 
PDF
The emerging world of mongo db csp
Carlos Sánchez Pérez
 
PPT
Mongo Bb - NoSQL tutorial
Mohan Rathour
 
PDF
MongoDB
wiTTyMinds1
 
PDF
Mongodb Introduction
Raghvendra Parashar
 
PPTX
lecture_34e.pptx
janibashashaik25
 
KEY
MongoDB Strange Loop 2009
Mike Dirolf
 
PDF
3-Mongodb and Mapreduce Programming.pdf
MarianJRuben
 
PPTX
Webinar: Building Your First MongoDB App
MongoDB
 
KEY
Introduction to MongoDB
Alex Bilbie
 
PDF
Mongo db eveningschemadesign
MongoDB APAC
 
KEY
MongoDB at CodeMash 2.0.1.0
Mike Dirolf
 
PDF
MongoDB
techwhizbang
 
PPTX
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
PDF
Mongo db basics
Claudio Montoya
 
PPTX
Introduction to MongoDB
Hossein Boustani
 
PPTX
UNIT-1 MongoDB.pptx
DharaDarji5
 
PPT
9. Document Oriented Databases
Fabio Fumarola
 
PDF
Building your first app with MongoDB
Norberto Leite
 
Intro To Mongo Db
chriskite
 
Mongo db
Gyanendra Yadav
 
The emerging world of mongo db csp
Carlos Sánchez Pérez
 
Mongo Bb - NoSQL tutorial
Mohan Rathour
 
MongoDB
wiTTyMinds1
 
Mongodb Introduction
Raghvendra Parashar
 
lecture_34e.pptx
janibashashaik25
 
MongoDB Strange Loop 2009
Mike Dirolf
 
3-Mongodb and Mapreduce Programming.pdf
MarianJRuben
 
Webinar: Building Your First MongoDB App
MongoDB
 
Introduction to MongoDB
Alex Bilbie
 
Mongo db eveningschemadesign
MongoDB APAC
 
MongoDB at CodeMash 2.0.1.0
Mike Dirolf
 
MongoDB
techwhizbang
 
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Mongo db basics
Claudio Montoya
 
Introduction to MongoDB
Hossein Boustani
 
UNIT-1 MongoDB.pptx
DharaDarji5
 
9. Document Oriented Databases
Fabio Fumarola
 
Building your first app with MongoDB
Norberto Leite
 
Ad

Recently uploaded (20)

PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
Doc9.....................................
SofiaCollazos
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 

Tech Gupshup Meetup On MongoDB - 24/06/2016

  • 2. In This Talk… • What is MongoDB? • Why use it? • Documents and Collections • Querying • JavaScript Shell • Schema Design
  • 4. Not a RDBMS • Mongo is not a relational database like MySQL • No transactions • No referential integrity • No joins • No schema, so no columns or rows • NoSQL
  • 5. Not a Key-Value Store • Mongo is not simply a key-value store like Redis • Stores structured data • Indexes • Map/Reduce • Sharding, GridFS, etc.
  • 6. Document-oriented Database • Records are JSON documents (actually BSON) • Stored in collections • No predefined schema • Docs in the same collection don’t even need to have the same fields • Operators for updates –$set, $inc, $push, $pop, etc.
  • 7. Mongo Document • user = { • name: "Frank Furter", • occupation: "A scientist", • location: "Transylvania" • }
  • 9. • Organizations of all sizes are adopting MongoDB because it enables them to build applications faster, handle highly diverse data types, and manage applications more efficiently at scale. • MongoDB’s flexible data model also means that your database schema can evolve with business requirements.
  • 10. It’s Web Scale! • Sharding built-in, automatic - As your deployments grow in terms of data volume and throughput, MongoDB scales easily with no downtime, and without changing your application. In contrast, to achieve scale with MySQL often requires significant, custom engineering work.
  • 11. • Asynchronous replication for failover and redundancy
  • 12. It’s Pretty Painless • Schemaless – No more configuring database columns with types – No more defining and managing migrations – Just stick your data in there, it’s fine • NoSQL – Mongo’s query language is basically JSON – The Mongo driver for your favorite language is really nice and officially supported – Handy JavaScript shell for the CLI
  • 13. It’s Pretty Painless /* First go create the database, the table, the schema, etc. */ mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $sql = "INSERT INTO users (name, age) VALUES ('Janet', 23)"; mysql_query($sql); $result = mysql_query("SELECT * FROM users WHERE age = 23"); $row = mysql_fetch_assoc($result); echo "Oh, " . $row['name'] . "!"; // prints "Oh, Janet!" $mongo = new Mongo(); // defaults to localhost with no auth $users = $mongo->test_db->users; // database and collection created implicitly $users->insert( array('name' => 'Brad', 'age' => 25) ); $user = $users->findOne( array('age' => 25) ); echo "Oh, " . $user->name . "!"; // prints "Oh, Brad!"
  • 15. Documents and Collections • Documents are the records – Like objects in OOP, or rows in RDBMS • Collections are groups of documents – Usually represent a top-level class in your app – Unlike RDBMS tables, no predefined schema • No foreign keys, so how do we reference other objects? – Don't! Just embed the sub-item in the parent doc – Or, use a key for references and deal with the fact that you don't get integrity or joins
  • 16. Embedded Objects • Documents can embed other documents – Used to efficiently represent a relation • For example: { name: 'Brad Majors', address: { street: 'Oak Terrace', city: 'Denton' } }
  • 18. Queries • Queries are documents • Query expression objects indicate a pattern to match – db.users.find( {last_name: 'Smith'} ) • Several query objects for advanced queries – db.users.find( {age: {$gte: 23} } ) – db.users.find( {age: {$in: [23,25]} } )
  • 19. Querying Embedded Objects • Exact match an entire embedded object – db.users.find( {address: {street: 'Oak Terrace', city: 'Denton'}} ) • Dot-notation for a partial match – db.users.find( {"address.city": 'Denton'} )
  • 21. JS Shell • Comes with MongoDB • Launch it with 'mongo' on the command-line
  • 23. • There is no predefined schema • Your application creates an schema with the objects it creates • The schema is implicit in the queries your application runs
  • 24. Schema Design • Use collections to represent the top-level classes of your application • But don't just make a collection for every object type – These aren't like tables in an RDBMS • Less normalization, more embedding
  • 25. Example • A blog post has an author, some text, and many comments • The comments are unique per post, but one author has many posts • How would you design this in SQL? • Let's look at how we might design it in Mongo
  • 26. Bad Schema Design: References • Collections for posts, authors, and comments • References by manually created ID post = { id: 150, author: 100, text: 'This is a pretty awesome post.', comments: [100, 105, 112] } author = { id: 100, name: 'Michael Arrington' posts: [150] } comment = { id: 105, text: 'Whatever this sux.' }
  • 27. Better Schema Design: Embedding • Collection for posts • Embed comments, author name post = { author: 'Michael Arrington', text: 'This is a pretty awesome post.', comments: [ 'Whatever this post sux.', 'I agree, lame!' ] }
  • 28. Benefits • Embedded objects brought back in the same query as parent object – Only 1 trip to the DB server required • Objects in the same collection are generally stored contiguously on disk
  • 29. Indexes • Mongo supports indexes to greatly improve query performance
  • 30. Schema Design Limitations • No referential integrity • High degree of denormalization means updating something in many places instead of one • Lack of predefined schema is a double-edged sword – Objects within a collection can be completely inconsistent in their fields
  • 32. Final Thoughts • MongoDB is fast • Very rapid development, open source • Document model is simple but powerful • Advanced features like map/reduce etc. are very compelling • Surprisingly great drivers for most languages