SlideShare a Scribd company logo
Chris Kite chriskite.com Intro to MongoDB
In This Talk… What is MongoDB? Why use it? Documents and Collections Querying JavaScript Shell Schema Design
What is MongoDB?
Not a RDBMS Mongo is not a relational database like MySQL No transactions No referential integrity No joins No schema, so no columns or rows NoSQL
Not a Key-Value Store Mongo is not simply a key-value store like Redis Stores structured data Rich query interface Indexes Map/Reduce Automatic sharding, GridFS, geospatial indexing, etc.
Document-oriented Database Records are JSON documents (actually BSON) Stored in collections No predefined schema Docs in the same collection don’t even need to have the same fields Atomic in-place operators for contention-free updates $set, $inc, $push, $pop, etc.
Mongo Document user = { 	 name: "Frank Furter", 	 occupation: "A scientist", 	 location: "Transylvania"   }
Why Use MongoDB?
It’s Stupid Fast! Anywhere from 2 to 10 times faster than MySQL Depends on which contrived benchmark you’re looking at Here’s one I just made up:
It’s Stupid Fast! About 50 times faster than CouchDB According to http://www.idiotsabound.com/did-i-mention-mongodb-is-fast-way-to-go-mongo 2 important points: It’s pretty quick Benchmarks are worthless unless you do them on your actual workload
It’s Web Scale! Sharding built-in, automatic, and *Just Works™ *Just Works™ guarantee applies only if you have a cluster of shard replica sets with config servers and routing servers and you define your own shard key(s) with appropriate uniformity and granularity Asynchronous replication for failover and redundancy
It’s Pretty Painless Schemaless No more configuring database columns with types No more defining and managing migrations Just stick your data in there, it’s fine NoSQL ORMs exist mostly because writing SQL sucks Mongo’s query language is basically JSON The Mongo driver for your favorite language is really nice and officially supported Handy JavaScript shell for the CLI
It’s Pretty Painless MySQL /* First go create the database, the table, the schema, etc. */ mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $sql = "INSERT INTO users (name, age) VALUES ('Janet', 23)"; mysql_query($sql); $result = mysql_query("SELECT * FROM users WHERE age = 23"); $row = mysql_fetch_assoc($result); echo "Oh, " . $row['name'] . "!"; // prints "Oh, Janet!" MongoDB $mongo = new Mongo(); // defaults to localhost with no auth $users = $mongo->test_db->users; // database and collection created implicitly $users->insert( array('name' => 'Brad', 'age' => 25) ); $user = $users->findOne( array('age' => 25) ); echo "Oh, " . $user->name . "!"; // prints "Oh, Brad!"
All the Cool Kids Are Doing It http://www.mongodb.org/display/DOCS/Production+Deployments
Documents and Collections
Documents and Collections Documents are the records Like objects in OOP, or rows in RDBMS Collections are groups of documents Usually represent a top-level class in your app Heterogeneous set Unlike RDBMS tables, no predefined schema No foreign keys, so how do we reference other objects? Don't! Just embed the sub-item in the parent doc Or, use a key for references and deal with the fact that you don't get integrity or joins
Embedded Objects Documents can embed other documents Used to efficiently represent a relation For example: {   name: 'Brad Majors',  address:     {      street: 'Oak Terrace',      city: 'Denton'    } }
Querying
Queries Queries are documents Query expression objects indicate a pattern to match db.users.find( {last_name: 'Smith'} ) Several query objects for advanced queries db.users.find( {age: {$gte: 23} } ) db.users.find( {age: {$in: [23,25]} } )
Querying Embedded Objects Exact match an entire embedded object db.users.find( {address: {street: 'Oak Terrace', city: 'Denton'}} ) Dot-notation for a partial match db.users.find( {"address.city": 'Denton'} )
JavaScript Shell
JS Shell Comes with MongoDB Launch it with 'mongo' on the command-line Try a simplified version at http://www.mongodb.org/ Great fit since Mongo docs are basically JSON
Live Demo If the tech demo gods allow it
Schema Design
I thought you said no schema? There is no predefined schema Your application creates an ad-hoc schema with the objects it creates The schema is implicit in the queries your application runs
Schema Design Use collections to represent the top-level classes of your application But don't just make a collection for every object type These aren't like tables in an RDBMS Less normalization, more embedding
Obligatory Blog Post Example A blog post has an author, some text, and many comments The comments are unique per post, but one author has many posts How would you design this in SQL? Let's look at how we might design it in Mongo
Bad Schema Design: References Collections for posts, authors, and comments References by manually created ID post = {  id: 150,  author: 100,  text: 'This is a pretty awesome post.',  comments: [100, 105, 112] } author = {  id: 100,  name: 'Michael Arrington'  posts: [150] } comment = {  id: 105,  text: 'Whatever this sux.' }
Better Schema Design: Embedding Collection for posts Embed comments, author name post = {  author: 'Michael Arrington',  text: 'This is a pretty awesome post.',  comments: [             'Whatever this post sux.',              'I agree, lame!'            ] }
Benefits Embedded objects brought back in the same query as parent object Only 1 trip to the DB server required Objects in the same collection are generally stored contiguously on disk Spatial locality = faster If the document model matches your domain well, it can be much easier to comprehend than nasty joins
Indexes Mongo supports indexes to greatly improve query performance No need to create in advance Create idempotent indexes in your app with "ensure_index"
Schema Design Limitations No referential integrity High degree of denormalization means updating something in many places instead of one Lack of predefined schema is a double-edged sword Hopefully you have a model in your app Objects within a collection can be completely inconsistent in their fields
Final Thoughts
Final Thoughts MongoDB is fast no matter how you slice it It achieves high performance by literally playing fast and loose with your data That's not necessarily a bad thing, just a tradeoff Very rapid development, open source Document model is simple but powerful Advanced features like map/reduce, geospatial indexing etc. are very compelling Surprisingly great drivers for most languages
Questions?
Thanks! These slides are online: http://bit.ly/intro_to_mongo

More Related Content

What's hot

Angular 8
Angular 8 Angular 8
Angular 8
Sunil OS
 
MongoDB at Scale
MongoDB at ScaleMongoDB at Scale
MongoDB at Scale
MongoDB
 
Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patterns
joergreichert
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
Habilelabs
 
Mongodb
MongodbMongodb
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
Hyphen Call
 
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfOracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
SrirakshaSrinivasan2
 
Mongo DB
Mongo DB Mongo DB
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101
Will Button
 
Introduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard BrokerIntroduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard Broker
Zohar Elkayam
 
Nest.js Introduction
Nest.js IntroductionNest.js Introduction
Nest.js Introduction
Takuya Tejima
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
Caserta
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
MongoDB
 
NestJS
NestJSNestJS
NestJS
Wilson Su
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
Amit Ghosh
 
Python and MongoDB
Python and MongoDBPython and MongoDB
Python and MongoDB
Christiano Anderson
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
botsplash.com
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
Lee Theobald
 
Mongodb vs mysql
Mongodb vs mysqlMongodb vs mysql
Mongodb vs mysql
hemal sharma
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
 

What's hot (20)

Angular 8
Angular 8 Angular 8
Angular 8
 
MongoDB at Scale
MongoDB at ScaleMongoDB at Scale
MongoDB at Scale
 
Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patterns
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Mongodb
MongodbMongodb
Mongodb
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfOracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101
 
Introduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard BrokerIntroduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard Broker
 
Nest.js Introduction
Nest.js IntroductionNest.js Introduction
Nest.js Introduction
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
 
NestJS
NestJSNestJS
NestJS
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
 
Python and MongoDB
Python and MongoDBPython and MongoDB
Python and MongoDB
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 
Mongodb vs mysql
Mongodb vs mysqlMongodb vs mysql
Mongodb vs mysql
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 

Similar to Intro To Mongo Db

Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/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
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 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 MongoDB
MongoDB
 
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
 
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Mydbops
 

Similar to Intro To Mongo Db (20)

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

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 

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