SlideShare a Scribd company logo
Chris Kitechriskite.comIntro to MongoDB
In This Talk…What is MongoDB?Why use it?Documents and CollectionsQueryingJavaScript ShellSchema Design
What is MongoDB?
Not a RDBMSMongo is not a relational database like MySQLNo transactionsNo referential integrityNo joinsNo schema, so no columns or rowsNoSQL
Not a Key-Value StoreMongo is not simply a key-value store like RedisStores structured dataRich query interfaceIndexesMap/ReduceAutomatic sharding, GridFS, geospatial indexing, etc.
Document-oriented DatabaseRecords are JSON documents (actually BSON)Stored in collectionsNo predefined schemaDocs in the same collection don’t even need to have the same fieldsAtomic in-place operators for contention-free updates$set, $inc, $push, $pop, etc.
Mongo Documentuser = {	 name: "Frank Furter",	 occupation: "A scientist",	 location: "Transylvania"  }
Why Use MongoDB?
It’s Stupid Fast!Anywhere from 2 to 10 times faster than MySQLDepends on which contrived benchmark you’re looking atHere’s one I just made up:
It’s Stupid Fast!About 50 times faster than CouchDBAccording to http://www.idiotsabound.com/did-i-mention-mongodb-is-fast-way-to-go-mongo2 important points:It’s pretty quickBenchmarks 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 granularityAsynchronous replication for failover and redundancy
It’s Pretty PainlessSchemalessNo more configuring database columns with typesNo more defining and managing migrationsJust stick your data in there, it’s fineNoSQLORMs exist mostly because writing SQL sucksMongo’s query language is basically JSONThe Mongo driver for your favorite language is really nice and officially supportedHandy JavaScript shell for the CLI
It’s Pretty PainlessMySQL/* 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 Ithttp://www.mongodb.org/display/DOCS/Production+Deployments
Documents and Collections
Documents and CollectionsDocuments are the recordsLike objects in OOP, or rows in RDBMSCollections are groups of documentsUsually represent a top-level class in your appHeterogeneous setUnlike RDBMS tables, no predefined schemaNo foreign keys, so how do we reference other objects?Don't! Just embed the sub-item in the parent docOr, use a key for references and deal with the fact that you don't get integrity or joins
Embedded ObjectsDocuments can embed other documentsUsed to efficiently represent a relationFor example:{  name: 'Brad Majors', address:    {     street: 'Oak Terrace',     city: 'Denton'   }}
Querying
QueriesQueries are documentsQuery expression objects indicate a pattern to matchdb.users.find( {last_name: 'Smith'} )Several query objects for advanced queriesdb.users.find( {age: {$gte: 23} } )db.users.find( {age: {$in: [23,25]} } )
Querying Embedded ObjectsExact match an entire embedded objectdb.users.find( {address: {street: 'Oak Terrace', city: 'Denton'}} )Dot-notation for a partial matchdb.users.find( {"address.city": 'Denton'} )
JavaScript Shell
JS ShellComes with MongoDBLaunch it with 'mongo' on the command-lineTry a simplified version at http://www.mongodb.org/Great fit since Mongo docs are basically JSON
Live DemoIf the tech demo gods allow it
Schema Design
I thought you said no schema?There is no predefined schemaYour application creates an ad-hoc schema with the objects it createsThe schema is implicit in the queries your application runs
Schema DesignUse collections to represent the top-level classes of your applicationBut don't just make a collection for every object typeThese aren't like tables in an RDBMSLess normalization, more embedding
Obligatory Blog Post ExampleA blog post has an author, some text, and many commentsThe comments are unique per post, but one author has many postsHow would you design this in SQL?Let's look at how we might design it in Mongo
Bad Schema Design: ReferencesCollections for posts, authors, and commentsReferences by manually created IDpost = { 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: EmbeddingCollection for postsEmbed comments, author namepost = { author: 'Michael Arrington', text: 'This is a pretty awesome post.', comments: [            'Whatever this post sux.',             'I agree, lame!'           ]}
BenefitsEmbedded objects brought back in the same query as parent objectOnly 1 trip to the DB server requiredObjects in the same collection are generally stored contiguously on diskSpatial locality = fasterIf the document model matches your domain well, it can be much easier to comprehend than nasty joins
IndexesMongo supports indexes to greatly improve query performanceNo need to create in advanceCreate idempotent indexes in your app with "ensure_index"
Schema Design LimitationsNo referential integrityHigh degree of denormalization means updating something in many places instead of oneLack of predefined schema is a double-edged swordHopefully you have a model in your appObjects within a collection can be completely inconsistent in their fields
Final Thoughts
Final ThoughtsMongoDB is fast no matter how you slice itIt achieves high performance by literally playing fast and loose with your dataThat's not necessarily a bad thing, just a tradeoffVery rapid development, open sourceDocument model is simple but powerfulAdvanced features like map/reduce, geospatial indexing etc. are very compellingSurprisingly great drivers for most languages
Questions?
Thanks!These slides are online:http://bit.ly/intro_to_mongo
Ad

More Related Content

What's hot (20)

Angular
AngularAngular
Angular
sridhiya
 
Hydra: A Vocabulary for Hypermedia-Driven Web APIs
Hydra: A Vocabulary for Hypermedia-Driven Web APIsHydra: A Vocabulary for Hypermedia-Driven Web APIs
Hydra: A Vocabulary for Hypermedia-Driven Web APIs
Markus Lanthaler
 
Synapse lakedatabase
Synapse lakedatabaseSynapse lakedatabase
Synapse lakedatabase
Ryoma Nagata
 
Apache Avro vs Protocol Buffers
Apache Avro vs Protocol BuffersApache Avro vs Protocol Buffers
Apache Avro vs Protocol Buffers
Seiya Mizuno
 
The Web Is Changing — From Strings to Things
The Web Is Changing — From Strings to ThingsThe Web Is Changing — From Strings to Things
The Web Is Changing — From Strings to Things
Markus Lanthaler
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway
 
MongoDB Tick Data Presentation
MongoDB Tick Data PresentationMongoDB Tick Data Presentation
MongoDB Tick Data Presentation
MongoDB
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
Universidade de São Paulo
 
S13 Oracle Database を Microsoft Azure 上で運用する為に~基本事項とベストプラクティス
S13 Oracle Database を Microsoft Azure 上で運用する為に~基本事項とベストプラクティスS13 Oracle Database を Microsoft Azure 上で運用する為に~基本事項とベストプラクティス
S13 Oracle Database を Microsoft Azure 上で運用する為に~基本事項とベストプラクティス
Microsoft Azure Japan
 
しばちょう先生が語る!オラクルデータベースの進化の歴史と最新技術動向#1
しばちょう先生が語る!オラクルデータベースの進化の歴史と最新技術動向#1しばちょう先生が語る!オラクルデータベースの進化の歴史と最新技術動向#1
しばちょう先生が語る!オラクルデータベースの進化の歴史と最新技術動向#1
オラクルエンジニア通信
 
spring-boot-fr.pdf
spring-boot-fr.pdfspring-boot-fr.pdf
spring-boot-fr.pdf
seydou4devops
 
AWS X-Rayによるアプリケーションの分析とデバッグ
AWS X-Rayによるアプリケーションの分析とデバッグAWS X-Rayによるアプリケーションの分析とデバッグ
AWS X-Rayによるアプリケーションの分析とデバッグ
Amazon Web Services Japan
 
【ことはじめ】 はじめてのコンテナ活用をクラウドで
【ことはじめ】 はじめてのコンテナ活用をクラウドで【ことはじめ】 はじめてのコンテナ活用をクラウドで
【ことはじめ】 はじめてのコンテナ活用をクラウドで
オラクルエンジニア通信
 
Oracle Container Engine for Kubernetes (OKE) ご紹介 [2021年5月版]
Oracle Container Engine for Kubernetes (OKE) ご紹介 [2021年5月版]Oracle Container Engine for Kubernetes (OKE) ご紹介 [2021年5月版]
Oracle Container Engine for Kubernetes (OKE) ご紹介 [2021年5月版]
オラクルエンジニア通信
 
Hibernate
HibernateHibernate
Hibernate
Ghazouani Mahdi
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
VMware Tanzu
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 
Spring Cloud Data Flow の紹介 #streamctjp
Spring Cloud Data Flow の紹介  #streamctjpSpring Cloud Data Flow の紹介  #streamctjp
Spring Cloud Data Flow の紹介 #streamctjp
Yahoo!デベロッパーネットワーク
 
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
Amazon Web Services Japan
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Hydra: A Vocabulary for Hypermedia-Driven Web APIs
Hydra: A Vocabulary for Hypermedia-Driven Web APIsHydra: A Vocabulary for Hypermedia-Driven Web APIs
Hydra: A Vocabulary for Hypermedia-Driven Web APIs
Markus Lanthaler
 
Synapse lakedatabase
Synapse lakedatabaseSynapse lakedatabase
Synapse lakedatabase
Ryoma Nagata
 
Apache Avro vs Protocol Buffers
Apache Avro vs Protocol BuffersApache Avro vs Protocol Buffers
Apache Avro vs Protocol Buffers
Seiya Mizuno
 
The Web Is Changing — From Strings to Things
The Web Is Changing — From Strings to ThingsThe Web Is Changing — From Strings to Things
The Web Is Changing — From Strings to Things
Markus Lanthaler
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway
 
MongoDB Tick Data Presentation
MongoDB Tick Data PresentationMongoDB Tick Data Presentation
MongoDB Tick Data Presentation
MongoDB
 
S13 Oracle Database を Microsoft Azure 上で運用する為に~基本事項とベストプラクティス
S13 Oracle Database を Microsoft Azure 上で運用する為に~基本事項とベストプラクティスS13 Oracle Database を Microsoft Azure 上で運用する為に~基本事項とベストプラクティス
S13 Oracle Database を Microsoft Azure 上で運用する為に~基本事項とベストプラクティス
Microsoft Azure Japan
 
しばちょう先生が語る!オラクルデータベースの進化の歴史と最新技術動向#1
しばちょう先生が語る!オラクルデータベースの進化の歴史と最新技術動向#1しばちょう先生が語る!オラクルデータベースの進化の歴史と最新技術動向#1
しばちょう先生が語る!オラクルデータベースの進化の歴史と最新技術動向#1
オラクルエンジニア通信
 
AWS X-Rayによるアプリケーションの分析とデバッグ
AWS X-Rayによるアプリケーションの分析とデバッグAWS X-Rayによるアプリケーションの分析とデバッグ
AWS X-Rayによるアプリケーションの分析とデバッグ
Amazon Web Services Japan
 
【ことはじめ】 はじめてのコンテナ活用をクラウドで
【ことはじめ】 はじめてのコンテナ活用をクラウドで【ことはじめ】 はじめてのコンテナ活用をクラウドで
【ことはじめ】 はじめてのコンテナ活用をクラウドで
オラクルエンジニア通信
 
Oracle Container Engine for Kubernetes (OKE) ご紹介 [2021年5月版]
Oracle Container Engine for Kubernetes (OKE) ご紹介 [2021年5月版]Oracle Container Engine for Kubernetes (OKE) ご紹介 [2021年5月版]
Oracle Container Engine for Kubernetes (OKE) ご紹介 [2021年5月版]
オラクルエンジニア通信
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
VMware Tanzu
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
Amazon Web Services Japan
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 

Viewers also liked (7)

Business considerations for node.js applications
Business considerations for node.js applicationsBusiness considerations for node.js applications
Business considerations for node.js applications
Aspenware
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Grant Goodale
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
Tata Consultancy Services
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
SpringPeople
 
MongoDB-Beginner tutorial explaining basic operation via mongo shell
MongoDB-Beginner tutorial explaining basic operation via mongo shellMongoDB-Beginner tutorial explaining basic operation via mongo shell
MongoDB-Beginner tutorial explaining basic operation via mongo shell
Priti Solanki
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
Alex Sharp
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
 
Business considerations for node.js applications
Business considerations for node.js applicationsBusiness considerations for node.js applications
Business considerations for node.js applications
Aspenware
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Grant Goodale
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
SpringPeople
 
MongoDB-Beginner tutorial explaining basic operation via mongo shell
MongoDB-Beginner tutorial explaining basic operation via mongo shellMongoDB-Beginner tutorial explaining basic operation via mongo shell
MongoDB-Beginner tutorial explaining basic operation via mongo shell
Priti Solanki
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
Alex Sharp
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
 
Ad

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
Mukesh Tilokani
 
Introduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopIntroduction to MongoDB and Workshop
Introduction to MongoDB and Workshop
AhmedabadJavaMeetup
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
Doug Green
 
MongoDB
MongoDBMongoDB
MongoDB
Steven Francia
 
Jumpstart: Building Your First MongoDB App
Jumpstart: Building Your First MongoDB AppJumpstart: Building Your First MongoDB App
Jumpstart: Building Your First MongoDB App
MongoDB
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
Norberto Leite
 
Mongo db
Mongo dbMongo db
Mongo db
Gyanendra Yadav
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
Lukas 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 Ming
Rick Copeland
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
S.Shayan Daneshvar
 
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
Rick 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 format
Forest Mars
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Justin 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 MongoDB
MongoDB
 
lecture_34e.pptx
lecture_34e.pptxlecture_34e.pptx
lecture_34e.pptx
janibashashaik25
 
Mongo learning series
Mongo learning series Mongo learning series
Mongo learning series
Prashanth Panduranga
 
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
JAX 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 Python
Rick Copeland
 
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
Carlos Sánchez Pérez
 
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
 
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
Mukesh Tilokani
 
Introduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopIntroduction to MongoDB and Workshop
Introduction to MongoDB and Workshop
AhmedabadJavaMeetup
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
Doug Green
 
Jumpstart: Building Your First MongoDB App
Jumpstart: Building Your First MongoDB AppJumpstart: Building Your First MongoDB App
Jumpstart: Building Your First MongoDB App
MongoDB
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
Norberto Leite
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
Lukas 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 Ming
Rick 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 SourceForge
Rick 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 format
Forest Mars
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Justin 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 MongoDB
MongoDB
 
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
JAX 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 Python
Rick 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
 
Ad

Recently uploaded (20)

AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
José Enrique López Rivera
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 
Buckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug LogsBuckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug Logs
Lynda Kane
 
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
José Enrique López Rivera
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 
Buckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug LogsBuckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug Logs
Lynda Kane
 
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 

Intro To Mongo Db

  • 2. In This Talk…What is MongoDB?Why use it?Documents and CollectionsQueryingJavaScript ShellSchema Design
  • 4. Not a RDBMSMongo is not a relational database like MySQLNo transactionsNo referential integrityNo joinsNo schema, so no columns or rowsNoSQL
  • 5. Not a Key-Value StoreMongo is not simply a key-value store like RedisStores structured dataRich query interfaceIndexesMap/ReduceAutomatic sharding, GridFS, geospatial indexing, etc.
  • 6. Document-oriented DatabaseRecords are JSON documents (actually BSON)Stored in collectionsNo predefined schemaDocs in the same collection don’t even need to have the same fieldsAtomic in-place operators for contention-free updates$set, $inc, $push, $pop, etc.
  • 7. Mongo Documentuser = { name: "Frank Furter", occupation: "A scientist", location: "Transylvania" }
  • 9. It’s Stupid Fast!Anywhere from 2 to 10 times faster than MySQLDepends on which contrived benchmark you’re looking atHere’s one I just made up:
  • 10. It’s Stupid Fast!About 50 times faster than CouchDBAccording to http://www.idiotsabound.com/did-i-mention-mongodb-is-fast-way-to-go-mongo2 important points:It’s pretty quickBenchmarks 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 granularityAsynchronous replication for failover and redundancy
  • 12. It’s Pretty PainlessSchemalessNo more configuring database columns with typesNo more defining and managing migrationsJust stick your data in there, it’s fineNoSQLORMs exist mostly because writing SQL sucksMongo’s query language is basically JSONThe Mongo driver for your favorite language is really nice and officially supportedHandy JavaScript shell for the CLI
  • 13. It’s Pretty PainlessMySQL/* 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 Ithttp://www.mongodb.org/display/DOCS/Production+Deployments
  • 16. Documents and CollectionsDocuments are the recordsLike objects in OOP, or rows in RDBMSCollections are groups of documentsUsually represent a top-level class in your appHeterogeneous setUnlike RDBMS tables, no predefined schemaNo foreign keys, so how do we reference other objects?Don't! Just embed the sub-item in the parent docOr, use a key for references and deal with the fact that you don't get integrity or joins
  • 17. Embedded ObjectsDocuments can embed other documentsUsed to efficiently represent a relationFor example:{ name: 'Brad Majors', address: { street: 'Oak Terrace', city: 'Denton' }}
  • 19. QueriesQueries are documentsQuery expression objects indicate a pattern to matchdb.users.find( {last_name: 'Smith'} )Several query objects for advanced queriesdb.users.find( {age: {$gte: 23} } )db.users.find( {age: {$in: [23,25]} } )
  • 20. Querying Embedded ObjectsExact match an entire embedded objectdb.users.find( {address: {street: 'Oak Terrace', city: 'Denton'}} )Dot-notation for a partial matchdb.users.find( {"address.city": 'Denton'} )
  • 22. JS ShellComes with MongoDBLaunch it with 'mongo' on the command-lineTry a simplified version at http://www.mongodb.org/Great fit since Mongo docs are basically JSON
  • 23. Live DemoIf the tech demo gods allow it
  • 25. I thought you said no schema?There is no predefined schemaYour application creates an ad-hoc schema with the objects it createsThe schema is implicit in the queries your application runs
  • 26. Schema DesignUse collections to represent the top-level classes of your applicationBut don't just make a collection for every object typeThese aren't like tables in an RDBMSLess normalization, more embedding
  • 27. Obligatory Blog Post ExampleA blog post has an author, some text, and many commentsThe comments are unique per post, but one author has many postsHow would you design this in SQL?Let's look at how we might design it in Mongo
  • 28. Bad Schema Design: ReferencesCollections for posts, authors, and commentsReferences by manually created IDpost = { 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: EmbeddingCollection for postsEmbed comments, author namepost = { author: 'Michael Arrington', text: 'This is a pretty awesome post.', comments: [ 'Whatever this post sux.', 'I agree, lame!' ]}
  • 30. BenefitsEmbedded objects brought back in the same query as parent objectOnly 1 trip to the DB server requiredObjects in the same collection are generally stored contiguously on diskSpatial locality = fasterIf the document model matches your domain well, it can be much easier to comprehend than nasty joins
  • 31. IndexesMongo supports indexes to greatly improve query performanceNo need to create in advanceCreate idempotent indexes in your app with "ensure_index"
  • 32. Schema Design LimitationsNo referential integrityHigh degree of denormalization means updating something in many places instead of oneLack of predefined schema is a double-edged swordHopefully you have a model in your appObjects within a collection can be completely inconsistent in their fields
  • 34. Final ThoughtsMongoDB is fast no matter how you slice itIt achieves high performance by literally playing fast and loose with your dataThat's not necessarily a bad thing, just a tradeoffVery rapid development, open sourceDocument model is simple but powerfulAdvanced features like map/reduce, geospatial indexing etc. are very compellingSurprisingly great drivers for most languages
  • 36. Thanks!These slides are online:http://bit.ly/intro_to_mongo