SlideShare a Scribd company logo
1 of 33
MongoDB
Tech Gupshup
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
• Indexes
• Map/Reduce
• Sharding, GridFS, 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
• Operators for updates
–$set, $inc, $push, $pop, etc.
Mongo Document
• user = {
• name: "Frank Furter",
• occupation: "A scientist",
• location: "Transylvania"
• }
Why Use MongoDB?
• Organizations of all sizes are adopting
MongoDB because it enables them to build
applications faster, handle highly diverse data
types, and manage applications more
efficiently at scale.
• MongoDB’s flexible data model also means
that your database schema can evolve with
business requirements.
It’s Web Scale!
• Sharding built-in, automatic - As your
deployments grow in terms of data volume and
throughput, MongoDB scales easily with no
downtime, and without changing your
application. In contrast, to achieve scale with
MySQL often requires significant, custom
engineering work.
• 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
– 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
/* 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!"
$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!"
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
– 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
Schema Design
• There is no predefined schema
• Your application creates an 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
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
Indexes
• Mongo supports indexes to greatly improve
query performance
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
– Objects within a collection can be completely
inconsistent in their fields
Final Thoughts
Final Thoughts
• MongoDB is fast
• Very rapid development, open source
• Document model is simple but powerful
• Advanced features like map/reduce etc. are
very compelling
• Surprisingly great drivers for most languages
Questions?

More Related Content

What's hot

jQuery - Web Engineering
jQuery - Web Engineering jQuery - Web Engineering
jQuery - Web Engineering adeel990
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBNeil Henegan
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOSgillygize
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.Oleg Shanyuk
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-CJuio Barros
 
A SOLID Design in InterSystems ObjectScript
A SOLID Design in InterSystems ObjectScriptA SOLID Design in InterSystems ObjectScript
A SOLID Design in InterSystems ObjectScriptAnastasiaDyubaylo
 
Velocity 101 in Cascade Server CMS, by Penny Harding
Velocity 101 in Cascade Server CMS, by Penny HardingVelocity 101 in Cascade Server CMS, by Penny Harding
Velocity 101 in Cascade Server CMS, by Penny Hardinghannonhill
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQueryAkshay Mathur
 
Mongo - an intermediate introduction
Mongo - an intermediate introductionMongo - an intermediate introduction
Mongo - an intermediate introductionnklmish
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesBenefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesAlex Nguyen
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012sullis
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentationMurat Çakal
 
Tips for writing Javascript for Drupal
Tips for writing Javascript for DrupalTips for writing Javascript for Drupal
Tips for writing Javascript for DrupalSergey Semashko
 
Difference between xml and json
Difference between xml and jsonDifference between xml and json
Difference between xml and jsonUmar Ali
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBMarakana Inc.
 

What's hot (20)

jQuery - Web Engineering
jQuery - Web Engineering jQuery - Web Engineering
jQuery - Web Engineering
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOS
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-C
 
Ajax xml json
Ajax xml jsonAjax xml json
Ajax xml json
 
Java script objects
Java script objectsJava script objects
Java script objects
 
A SOLID Design in InterSystems ObjectScript
A SOLID Design in InterSystems ObjectScriptA SOLID Design in InterSystems ObjectScript
A SOLID Design in InterSystems ObjectScript
 
Velocity 101 in Cascade Server CMS, by Penny Harding
Velocity 101 in Cascade Server CMS, by Penny HardingVelocity 101 in Cascade Server CMS, by Penny Harding
Velocity 101 in Cascade Server CMS, by Penny Harding
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
 
CouchDB in The Room
CouchDB in The RoomCouchDB in The Room
CouchDB in The Room
 
Mongo - an intermediate introduction
Mongo - an intermediate introductionMongo - an intermediate introduction
Mongo - an intermediate introduction
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesBenefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
 
AJAX
AJAXAJAX
AJAX
 
Tips for writing Javascript for Drupal
Tips for writing Javascript for DrupalTips for writing Javascript for Drupal
Tips for writing Javascript for Drupal
 
Difference between xml and json
Difference between xml and jsonDifference between xml and json
Difference between xml and json
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDB
 
Elastic Search
Elastic SearchElastic Search
Elastic Search
 

Similar to Tech Gupshup Meetup On MongoDB - 24/06/2016

Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Dbchriskite
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMetatagg Solutions
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBSean Laurent
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesignMongoDB APAC
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlTO THE NEW | Technology
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...Prasoon Kumar
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentosConceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentosMongoDB
 
MongoDB & NoSQL 101
 MongoDB & NoSQL 101 MongoDB & NoSQL 101
MongoDB & NoSQL 101Jollen Chen
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCupWebGeek Philippines
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRailsMike Dirolf
 
Sqlite
SqliteSqlite
SqliteKumar
 

Similar to Tech Gupshup Meetup On MongoDB - 24/06/2016 (20)

Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
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
 
phptut4
phptut4phptut4
phptut4
 
phptut4
phptut4phptut4
phptut4
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesign
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
 
MongoDB_ppt.pptx
MongoDB_ppt.pptxMongoDB_ppt.pptx
MongoDB_ppt.pptx
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentosConceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
 
MongoDB & NoSQL 101
 MongoDB & NoSQL 101 MongoDB & NoSQL 101
MongoDB & NoSQL 101
 
mongodb_DS.pptx
mongodb_DS.pptxmongodb_DS.pptx
mongodb_DS.pptx
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRails
 
Sqlite
SqliteSqlite
Sqlite
 

Recently uploaded

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Recently uploaded (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Tech Gupshup Meetup On MongoDB - 24/06/2016

  • 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 • Indexes • Map/Reduce • Sharding, GridFS, 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 • Operators for updates –$set, $inc, $push, $pop, etc.
  • 7. Mongo Document • user = { • name: "Frank Furter", • occupation: "A scientist", • location: "Transylvania" • }
  • 9. • Organizations of all sizes are adopting MongoDB because it enables them to build applications faster, handle highly diverse data types, and manage applications more efficiently at scale. • MongoDB’s flexible data model also means that your database schema can evolve with business requirements.
  • 10. It’s Web Scale! • Sharding built-in, automatic - As your deployments grow in terms of data volume and throughput, MongoDB scales easily with no downtime, and without changing your application. In contrast, to achieve scale with MySQL often requires significant, custom engineering work.
  • 11. • 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 – 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 /* 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!" $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!"
  • 15. 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 – 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
  • 16. Embedded Objects • Documents can embed other documents – Used to efficiently represent a relation • For example: { name: 'Brad Majors', address: { street: 'Oak Terrace', city: 'Denton' } }
  • 18. 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]} } )
  • 19. 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'} )
  • 21. JS Shell • Comes with MongoDB • Launch it with 'mongo' on the command-line
  • 23. • There is no predefined schema • Your application creates an schema with the objects it creates • The schema is implicit in the queries your application runs
  • 24. 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
  • 25. 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
  • 26. 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.' }
  • 27. 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!' ] }
  • 28. 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
  • 29. Indexes • Mongo supports indexes to greatly improve query performance
  • 30. 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 – Objects within a collection can be completely inconsistent in their fields
  • 32. Final Thoughts • MongoDB is fast • Very rapid development, open source • Document model is simple but powerful • Advanced features like map/reduce etc. are very compelling • Surprisingly great drivers for most languages