SlideShare a Scribd company logo
1 of 36
Chris Kite chriskite.com Intro to MongoDB
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 Rich query interface Indexes Map/Reduce Automatic sharding, GridFS, geospatial indexing, 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 Atomic in-place operators for contention-free updates $set, $inc, $push, $pop, etc.
Mongo Document user = { 	 name: "Frank Furter", 	 occupation: "A scientist", 	 location: "Transylvania"   }
Why Use MongoDB?
It’s Stupid Fast! Anywhere from 2 to 10 times faster than MySQL Depends on which contrived benchmark you’re looking at Here’s one I just made up:
It’s Stupid Fast! About 50 times faster than CouchDB According to http://www.idiotsabound.com/did-i-mention-mongodb-is-fast-way-to-go-mongo 2 important points: It’s pretty quick Benchmarks are worthless unless you do them on your actual workload
It’s Web Scale! Sharding built-in, automatic, and *Just Works™ *Just Works™ guarantee applies only if you have a cluster of shard replica sets with config servers and routing servers and you define your own shard key(s) with appropriate uniformity and granularity 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 ORMs exist mostly because writing SQL sucks 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 MySQL /* 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!" MongoDB $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!"
All the Cool Kids Are Doing It http://www.mongodb.org/display/DOCS/Production+Deployments
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 Heterogeneous set 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 Try a simplified version at http://www.mongodb.org/ Great fit since Mongo docs are basically JSON
Live Demo If the tech demo gods allow it
Schema Design
I thought you said no schema? There is no predefined schema Your application creates an ad-hoc 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
Obligatory Blog Post 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 Spatial locality = faster If the document model matches your domain well, it can be much easier to comprehend than nasty joins
Indexes Mongo supports indexes to greatly improve query performance No need to create in advance Create idempotent indexes in your app with "ensure_index"
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 Hopefully you have a model in your app Objects within a collection can be completely inconsistent in their fields
Final Thoughts
Final Thoughts MongoDB is fast no matter how you slice it It achieves high performance by literally playing fast and loose with your data That's not necessarily a bad thing, just a tradeoff Very rapid development, open source Document model is simple but powerful Advanced features like map/reduce, geospatial indexing etc. are very compelling Surprisingly great drivers for most languages
Questions?
Thanks! These slides are online: http://bit.ly/intro_to_mongo

More Related Content

What's hot

Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB Habilelabs
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineJason Terpko
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBNodeXperts
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentationHyphen Call
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDBAlex Sharp
 
Sql vs NoSQL
Sql vs NoSQLSql vs NoSQL
Sql vs NoSQLRTigger
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMongoDB
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPTGo4Guru
 
How queries work with sharding
How queries work with shardingHow queries work with sharding
How queries work with shardingMongoDB
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operationsanujaggarwal49
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL DatabasesDerek Stainer
 
PostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaPostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaEdureka!
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query OptimizationMongoDB
 
SQL vs. NoSQL Databases
SQL vs. NoSQL DatabasesSQL vs. NoSQL Databases
SQL vs. NoSQL DatabasesOsama Jomaa
 

What's hot (20)

Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Sql vs NoSQL
Sql vs NoSQLSql vs NoSQL
Sql vs NoSQL
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
SQL & NoSQL
SQL & NoSQLSQL & NoSQL
SQL & NoSQL
 
How queries work with sharding
How queries work with shardingHow queries work with sharding
How queries work with sharding
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
Mongodb
MongodbMongodb
Mongodb
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL Databases
 
PostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaPostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | Edureka
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query Optimization
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
SQL vs. NoSQL Databases
SQL vs. NoSQL DatabasesSQL vs. NoSQL Databases
SQL vs. NoSQL Databases
 

Similar to Intro To Mongo Db

Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016Mukesh Tilokani
 
Introduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopIntroduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopAhmedabadJavaMeetup
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDoug Green
 
Jumpstart: Building Your First MongoDB App
Jumpstart: Building Your First MongoDB AppJumpstart: Building Your First MongoDB App
Jumpstart: Building Your First MongoDB AppMongoDB
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
Compass Framework
Compass FrameworkCompass Framework
Compass FrameworkLukas Vlcek
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeAllura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeRick Copeland
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP formatForest Mars
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBJustin Smestad
 
MongoDB.local Sydney: An Introduction to Document Databases with MongoDB
MongoDB.local Sydney: An Introduction to Document Databases with MongoDBMongoDB.local Sydney: An Introduction to Document Databases with MongoDB
MongoDB.local Sydney: An Introduction to Document Databases with MongoDBMongoDB
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardJAX London
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRick Copeland
 
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...Mydbops
 

Similar to Intro To Mongo Db (20)

Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016
 
Introduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopIntroduction to MongoDB and Workshop
Introduction to MongoDB and Workshop
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
 
MongoDB
MongoDBMongoDB
MongoDB
 
Jumpstart: Building Your First MongoDB App
Jumpstart: Building Your First MongoDB AppJumpstart: Building Your First MongoDB App
Jumpstart: Building Your First MongoDB App
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
Mongo db
Mongo dbMongo db
Mongo db
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeAllura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForge
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP format
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB.local Sydney: An Introduction to Document Databases with MongoDB
MongoDB.local Sydney: An Introduction to Document Databases with MongoDBMongoDB.local Sydney: An Introduction to Document Databases with MongoDB
MongoDB.local Sydney: An Introduction to Document Databases with MongoDB
 
lecture_34e.pptx
lecture_34e.pptxlecture_34e.pptx
lecture_34e.pptx
 
Mongo learning series
Mongo learning series Mongo learning series
Mongo learning series
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and Python
 
The emerging world of mongo db csp
The emerging world of mongo db   cspThe emerging world of mongo db   csp
The emerging world of mongo db csp
 
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
 

Recently uploaded

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Recently uploaded (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

Intro To Mongo Db

  • 1. Chris Kite chriskite.com Intro to MongoDB
  • 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 Rich query interface Indexes Map/Reduce Automatic sharding, GridFS, geospatial indexing, 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 Atomic in-place operators for contention-free updates $set, $inc, $push, $pop, etc.
  • 7. Mongo Document user = { name: "Frank Furter", occupation: "A scientist", location: "Transylvania" }
  • 9. It’s Stupid Fast! Anywhere from 2 to 10 times faster than MySQL Depends on which contrived benchmark you’re looking at Here’s one I just made up:
  • 10. It’s Stupid Fast! About 50 times faster than CouchDB According to http://www.idiotsabound.com/did-i-mention-mongodb-is-fast-way-to-go-mongo 2 important points: It’s pretty quick Benchmarks are worthless unless you do them on your actual workload
  • 11. It’s Web Scale! Sharding built-in, automatic, and *Just Works™ *Just Works™ guarantee applies only if you have a cluster of shard replica sets with config servers and routing servers and you define your own shard key(s) with appropriate uniformity and granularity 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 ORMs exist mostly because writing SQL sucks 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 MySQL /* 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!" MongoDB $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!"
  • 14. All the Cool Kids Are Doing It http://www.mongodb.org/display/DOCS/Production+Deployments
  • 16. 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 Heterogeneous set 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
  • 17. Embedded Objects Documents can embed other documents Used to efficiently represent a relation For example: { name: 'Brad Majors', address: { street: 'Oak Terrace', city: 'Denton' } }
  • 19. 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]} } )
  • 20. 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'} )
  • 22. JS Shell Comes with MongoDB Launch it with 'mongo' on the command-line Try a simplified version at http://www.mongodb.org/ Great fit since Mongo docs are basically JSON
  • 23. Live Demo If the tech demo gods allow it
  • 25. I thought you said no schema? There is no predefined schema Your application creates an ad-hoc schema with the objects it creates The schema is implicit in the queries your application runs
  • 26. 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
  • 27. Obligatory Blog Post 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
  • 28. 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.' }
  • 29. 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!' ] }
  • 30. 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 Spatial locality = faster If the document model matches your domain well, it can be much easier to comprehend than nasty joins
  • 31. Indexes Mongo supports indexes to greatly improve query performance No need to create in advance Create idempotent indexes in your app with "ensure_index"
  • 32. 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 Hopefully you have a model in your app Objects within a collection can be completely inconsistent in their fields
  • 34. Final Thoughts MongoDB is fast no matter how you slice it It achieves high performance by literally playing fast and loose with your data That's not necessarily a bad thing, just a tradeoff Very rapid development, open source Document model is simple but powerful Advanced features like map/reduce, geospatial indexing etc. are very compelling Surprisingly great drivers for most languages
  • 36. Thanks! These slides are online: http://bit.ly/intro_to_mongo