SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDBAlex Sharp
 
Mongo DB 성능최적화 전략
Mongo DB 성능최적화 전략Mongo DB 성능최적화 전략
Mongo DB 성능최적화 전략Jin wook
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBLee Theobald
 
A Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerA Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerMongoDB
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineJason Terpko
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMydbops
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpen Gurukul
 
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadinC* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadinDataStax Academy
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Stamatis Zampetakis
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query OptimizationMongoDB
 

Was ist angesagt? (20)

Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Mongo DB 성능최적화 전략
Mongo DB 성능최적화 전략Mongo DB 성능최적화 전략
Mongo DB 성능최적화 전략
 
Tuning Linux for MongoDB
Tuning Linux for MongoDBTuning Linux for MongoDB
Tuning Linux for MongoDB
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
MongoDB
MongoDBMongoDB
MongoDB
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 
A Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerA Technical Introduction to WiredTiger
A Technical Introduction to WiredTiger
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 
MongoDB
MongoDBMongoDB
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To Transactions
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadinC* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
 
Ash and awr deep dive hotsos
Ash and awr deep dive hotsosAsh and awr deep dive hotsos
Ash and awr deep dive hotsos
 
One PDB to go, please!
One PDB to go, please!One PDB to go, please!
One PDB to go, please!
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21
 
Postgresql tutorial
Postgresql tutorialPostgresql tutorial
Postgresql tutorial
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query Optimization
 

Ähnlich wie 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
 

Ähnlich wie 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...
 

Kürzlich hochgeladen

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Kürzlich hochgeladen (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

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