際際滷

際際滷Share a Scribd company logo
Chris Kitechriskite.comIntro to MongoDB
In This TalkWhat 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 dont 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?
Its Stupid Fast!Anywhere from 2 to 10 times faster than MySQLDepends on which contrived benchmark youre looking atHeres one I just made up:
Its 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:Its pretty quickBenchmarks are worthless unless you do them on your actual workload
Its 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
Its Pretty PainlessSchemalessNo more configuring database columns with typesNo more defining and managing migrationsJust stick your data in there, its fineNoSQLORMs exist mostly because writing SQL sucksMongos query language is basically JSONThe Mongo driver for your favorite language is really nice and officially supportedHandy JavaScript shell for the CLI
Its 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

More Related Content

What's hot (20)

MongoDB
MongoDBMongoDB
MongoDB
nikhil2807
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
HabileLabs
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
Hyphen Call
Oracle REST Data Services: Options for your Web Services
Oracle REST Data Services: Options for your Web ServicesOracle REST Data Services: Options for your Web Services
Oracle REST Data Services: Options for your Web Services
Jeff Smith
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
Eyal Vardi
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Mike Dirolf
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
David Lien
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
Malla Reddy University
How queries work with sharding
How queries work with shardingHow queries work with sharding
How queries work with sharding
MongoDB
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
Universidade de S達o Paulo
Mongo db 豕覯蠏
Mongo db 豕覯蠏Mongo db 豕覯蠏
Mongo db 豕覯蠏
beom kyun choi
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
Caserta
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
Altinity Ltd
MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud Operation
Edureka!
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
MongoDB
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
Surya937648
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
Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDB
MongoDB
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
HabileLabs
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
Hyphen Call
Oracle REST Data Services: Options for your Web Services
Oracle REST Data Services: Options for your Web ServicesOracle REST Data Services: Options for your Web Services
Oracle REST Data Services: Options for your Web Services
Jeff Smith
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
Eyal Vardi
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Mike Dirolf
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
David Lien
How queries work with sharding
How queries work with shardingHow queries work with sharding
How queries work with sharding
MongoDB
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
Caserta
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
Altinity Ltd
MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud Operation
Edureka!
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
MongoDB
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
Surya937648
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
Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDB
MongoDB

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

Recently uploaded (20)

UiPath Community Dubai: Discover Unified Apps
UiPath Community Dubai: Discover Unified AppsUiPath Community Dubai: Discover Unified Apps
UiPath Community Dubai: Discover Unified Apps
UiPathCommunity
Introduction to PHP from Beginning to End
Introduction to PHP from Beginning to EndIntroduction to PHP from Beginning to End
Introduction to PHP from Beginning to End
christopherneo4
TrustArc Webinar - Data Privacy and Cyber Security: A Symbiotic Relationship
TrustArc Webinar - Data Privacy and Cyber Security: A Symbiotic RelationshipTrustArc Webinar - Data Privacy and Cyber Security: A Symbiotic Relationship
TrustArc Webinar - Data Privacy and Cyber Security: A Symbiotic Relationship
TrustArc
Model Context Protocol (MCP): The Future of AI | Bluebash
Model Context Protocol (MCP): The Future of AI | BluebashModel Context Protocol (MCP): The Future of AI | Bluebash
Model Context Protocol (MCP): The Future of AI | Bluebash
Bluebash
The-Future-of-Artificial-Intelligence-Transforming-Industries-and-Society
The-Future-of-Artificial-Intelligence-Transforming-Industries-and-SocietyThe-Future-of-Artificial-Intelligence-Transforming-Industries-and-Society
The-Future-of-Artificial-Intelligence-Transforming-Industries-and-Society
KARLO
Webinar - Protecting Your Microsoft 365 Data
Webinar - Protecting Your Microsoft 365 DataWebinar - Protecting Your Microsoft 365 Data
Webinar - Protecting Your Microsoft 365 Data
MSP360
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdfCybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Joe Shenouda
AC1-intro-agenda-Agile concepts in an enterprise environment
AC1-intro-agenda-Agile concepts in an enterprise environmentAC1-intro-agenda-Agile concepts in an enterprise environment
AC1-intro-agenda-Agile concepts in an enterprise environment
Dennis Van Aelst
Build With AI X GDG Harare Beginners .pdf
Build With AI X GDG Harare Beginners .pdfBuild With AI X GDG Harare Beginners .pdf
Build With AI X GDG Harare Beginners .pdf
Google Developer Group - Harare
SAP Automation with UiPath: Top 10 Use Cases Across FI/MM/SD/Basis/PP Modules...
SAP Automation with UiPath: Top 10 Use Cases Across FI/MM/SD/Basis/PP Modules...SAP Automation with UiPath: Top 10 Use Cases Across FI/MM/SD/Basis/PP Modules...
SAP Automation with UiPath: Top 10 Use Cases Across FI/MM/SD/Basis/PP Modules...
DianaGray10
AI in Bioinformatics: How Artificial Intelligence is Revolutionizing Healthca...
AI in Bioinformatics: How Artificial Intelligence is Revolutionizing Healthca...AI in Bioinformatics: How Artificial Intelligence is Revolutionizing Healthca...
AI in Bioinformatics: How Artificial Intelligence is Revolutionizing Healthca...
Vadim Nareyko
AC3-SCRUM-Agile concepts in an enterprise environment
AC3-SCRUM-Agile concepts in an enterprise environmentAC3-SCRUM-Agile concepts in an enterprise environment
AC3-SCRUM-Agile concepts in an enterprise environment
Dennis Van Aelst
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD TechnicianRicardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno
Elevating AI Workflows: Integrating Azure API Management and Azure Functions ...
Elevating AI Workflows: Integrating Azure API Management and Azure Functions ...Elevating AI Workflows: Integrating Azure API Management and Azure Functions ...
Elevating AI Workflows: Integrating Azure API Management and Azure Functions ...
Callon Campbell
H2O Generative AI Starter Track - Support Presentation 際際滷s.pdf
H2O Generative AI Starter Track - Support Presentation 際際滷s.pdfH2O Generative AI Starter Track - Support Presentation 際際滷s.pdf
H2O Generative AI Starter Track - Support Presentation 際際滷s.pdf
Sri Ambati
Fran巽ais Patch Tuesday - Avril
Fran巽ais Patch Tuesday - AvrilFran巽ais Patch Tuesday - Avril
Fran巽ais Patch Tuesday - Avril
Ivanti
Meet, Greet, and Explore Agentic AI with UiPath Scotland
Meet, Greet, and Explore Agentic AI with UiPath ScotlandMeet, Greet, and Explore Agentic AI with UiPath Scotland
Meet, Greet, and Explore Agentic AI with UiPath Scotland
UiPathCommunity
Laravel Crud Tutorial Basic Step by Stepy S
Laravel Crud Tutorial Basic Step by Stepy SLaravel Crud Tutorial Basic Step by Stepy S
Laravel Crud Tutorial Basic Step by Stepy S
christopherneo4
CitrineOS: Bridging the Past and Future of EV Charging with OCPP 1.6 & 2.x Su...
CitrineOS: Bridging the Past and Future of EV Charging with OCPP 1.6 & 2.x Su...CitrineOS: Bridging the Past and Future of EV Charging with OCPP 1.6 & 2.x Su...
CitrineOS: Bridging the Past and Future of EV Charging with OCPP 1.6 & 2.x Su...
DanBrown980551
Presentation Session 4 -Agent Builder.pdf
Presentation Session 4 -Agent Builder.pdfPresentation Session 4 -Agent Builder.pdf
Presentation Session 4 -Agent Builder.pdf
Mukesh Kala
UiPath Community Dubai: Discover Unified Apps
UiPath Community Dubai: Discover Unified AppsUiPath Community Dubai: Discover Unified Apps
UiPath Community Dubai: Discover Unified Apps
UiPathCommunity
Introduction to PHP from Beginning to End
Introduction to PHP from Beginning to EndIntroduction to PHP from Beginning to End
Introduction to PHP from Beginning to End
christopherneo4
TrustArc Webinar - Data Privacy and Cyber Security: A Symbiotic Relationship
TrustArc Webinar - Data Privacy and Cyber Security: A Symbiotic RelationshipTrustArc Webinar - Data Privacy and Cyber Security: A Symbiotic Relationship
TrustArc Webinar - Data Privacy and Cyber Security: A Symbiotic Relationship
TrustArc
Model Context Protocol (MCP): The Future of AI | Bluebash
Model Context Protocol (MCP): The Future of AI | BluebashModel Context Protocol (MCP): The Future of AI | Bluebash
Model Context Protocol (MCP): The Future of AI | Bluebash
Bluebash
The-Future-of-Artificial-Intelligence-Transforming-Industries-and-Society
The-Future-of-Artificial-Intelligence-Transforming-Industries-and-SocietyThe-Future-of-Artificial-Intelligence-Transforming-Industries-and-Society
The-Future-of-Artificial-Intelligence-Transforming-Industries-and-Society
KARLO
Webinar - Protecting Your Microsoft 365 Data
Webinar - Protecting Your Microsoft 365 DataWebinar - Protecting Your Microsoft 365 Data
Webinar - Protecting Your Microsoft 365 Data
MSP360
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdfCybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Joe Shenouda
AC1-intro-agenda-Agile concepts in an enterprise environment
AC1-intro-agenda-Agile concepts in an enterprise environmentAC1-intro-agenda-Agile concepts in an enterprise environment
AC1-intro-agenda-Agile concepts in an enterprise environment
Dennis Van Aelst
SAP Automation with UiPath: Top 10 Use Cases Across FI/MM/SD/Basis/PP Modules...
SAP Automation with UiPath: Top 10 Use Cases Across FI/MM/SD/Basis/PP Modules...SAP Automation with UiPath: Top 10 Use Cases Across FI/MM/SD/Basis/PP Modules...
SAP Automation with UiPath: Top 10 Use Cases Across FI/MM/SD/Basis/PP Modules...
DianaGray10
AI in Bioinformatics: How Artificial Intelligence is Revolutionizing Healthca...
AI in Bioinformatics: How Artificial Intelligence is Revolutionizing Healthca...AI in Bioinformatics: How Artificial Intelligence is Revolutionizing Healthca...
AI in Bioinformatics: How Artificial Intelligence is Revolutionizing Healthca...
Vadim Nareyko
AC3-SCRUM-Agile concepts in an enterprise environment
AC3-SCRUM-Agile concepts in an enterprise environmentAC3-SCRUM-Agile concepts in an enterprise environment
AC3-SCRUM-Agile concepts in an enterprise environment
Dennis Van Aelst
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD TechnicianRicardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno
Elevating AI Workflows: Integrating Azure API Management and Azure Functions ...
Elevating AI Workflows: Integrating Azure API Management and Azure Functions ...Elevating AI Workflows: Integrating Azure API Management and Azure Functions ...
Elevating AI Workflows: Integrating Azure API Management and Azure Functions ...
Callon Campbell
H2O Generative AI Starter Track - Support Presentation 際際滷s.pdf
H2O Generative AI Starter Track - Support Presentation 際際滷s.pdfH2O Generative AI Starter Track - Support Presentation 際際滷s.pdf
H2O Generative AI Starter Track - Support Presentation 際際滷s.pdf
Sri Ambati
Fran巽ais Patch Tuesday - Avril
Fran巽ais Patch Tuesday - AvrilFran巽ais Patch Tuesday - Avril
Fran巽ais Patch Tuesday - Avril
Ivanti
Meet, Greet, and Explore Agentic AI with UiPath Scotland
Meet, Greet, and Explore Agentic AI with UiPath ScotlandMeet, Greet, and Explore Agentic AI with UiPath Scotland
Meet, Greet, and Explore Agentic AI with UiPath Scotland
UiPathCommunity
Laravel Crud Tutorial Basic Step by Stepy S
Laravel Crud Tutorial Basic Step by Stepy SLaravel Crud Tutorial Basic Step by Stepy S
Laravel Crud Tutorial Basic Step by Stepy S
christopherneo4
CitrineOS: Bridging the Past and Future of EV Charging with OCPP 1.6 & 2.x Su...
CitrineOS: Bridging the Past and Future of EV Charging with OCPP 1.6 & 2.x Su...CitrineOS: Bridging the Past and Future of EV Charging with OCPP 1.6 & 2.x Su...
CitrineOS: Bridging the Past and Future of EV Charging with OCPP 1.6 & 2.x Su...
DanBrown980551
Presentation Session 4 -Agent Builder.pdf
Presentation Session 4 -Agent Builder.pdfPresentation Session 4 -Agent Builder.pdf
Presentation Session 4 -Agent Builder.pdf
Mukesh Kala

Intro To Mongo Db

  • 2. In This TalkWhat 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 dont 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. Its Stupid Fast!Anywhere from 2 to 10 times faster than MySQLDepends on which contrived benchmark youre looking atHeres one I just made up:
  • 10. Its 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:Its pretty quickBenchmarks are worthless unless you do them on your actual workload
  • 11. Its 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. Its Pretty PainlessSchemalessNo more configuring database columns with typesNo more defining and managing migrationsJust stick your data in there, its fineNoSQLORMs exist mostly because writing SQL sucksMongos query language is basically JSONThe Mongo driver for your favorite language is really nice and officially supportedHandy JavaScript shell for the CLI
  • 13. Its 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