際際滷

際際滷Share a Scribd company logo
MongoDB
The Basics
1. MongoDB has the same concept of a database with which you are
likely already familiar
2. A database can have zero or more collections.
3. Collections are made up of zero or more documents.
4. A document is made up of one or more fields
5. Indexes in MongoDB function mostly like their RDBMS counterparts.
6. Cursors are different than the other five concepts but they are
important enough, and often overlooked
Examples : 1
 db.unicorns.insert({name: 'Aurora, gender: 'f', weight: 450})
 db.unicorns.find()
 db.unicorns.insert({name: 'Horny',dob: new Date(1992,2,13,7,47),
loves: ['carrot','papaya'],weight: 600,gender: 'm',vampires: 63});
The special $lt, $lte, $gt, $gte
 db.unicorns.find({gender: 'm',weight: {$gt: 700}})
 db.unicorns.find({gender: {$ne: 'f'},weight: {$gte: 701}})
Examples : 2
 db.unicorns.find({vampires: {$exists: false}})
 db.unicorns.find({loves: {$in:['apple','orange']}})
 db.unicorns.find({gender: 'f, $or: [{loves: 'apple'},{weight: {$lt:
500}}]})
 db.unicorns.find({_id: ObjectId("TheObjectId")})
Updating Document
 db.unicorns.update({name: 'Roooooodles}, {weight: 590})
 db.unicorns.update({weight: 590}, {$set: {name: 'Roooooodles',dob:
new Date(1979, 7, 18, 18, 44), loves: ['apple'],gender: 'm',vampires:
99}})
 db.unicorns.update({name: 'Roooooodles'},{$set: {weight: 590}})
 db.unicorns.update({name: 'Pilot'},{$inc: {vampires: -2}})
 db.unicorns.update({name: 'Aurora'},{$push: {loves: 'sugar'}})
Upserts
 db.hits.update({page: 'unicorns}, {$inc: {hits: 1}});
 db.hits.update({page: 'unicorns}, {$inc: {hits: 1}}, {upsert:true});
 Multiple Updates
 db.unicorns.update({},{$set: {vaccinated: true }});
 db.unicorns.update({},{$set: {vaccinated: true }},{multi:true});
Find
 db.unicorns.find({}, {name: 1});
 db.unicorns.find().sort({weight: -1})
 db.unicorns.find().sort({name: 1,vampires: -1})
 db.unicorns.find().sort({weight: -1}).limit(2).skip(1)
 db.unicorns.count({vampires: {$gt: 50}})
 db.unicorns.find({vampires: {$gt: 50}}).count()
Data Modeling
 No Joins
 The first and most fundamental difference that youll need to get comfortable
with is MongoDBs lack of joins.
 joins are generally seen as non-scalable
 Embedded Documents
 db.employees.insert({_id: ObjectId("4d85c7039ab0fd70a117d734"),name:
'Ghanima',family: {mother: 'Chani',father: 'Paul',brother:
ObjectId("4d85c7039ab0fd70a117d730")}})
Denormalization
 Yet another alternative to using joins is to denormalize your data.
Historically, denormalization was reserved for performance-sensitive code,
or when data should be snapshotted (like in an audit log). However, with
the ever growing popularity of NoSQL, many of which dont have joins,
denormalization as part of normal modeling is becoming increasingly
common.
 The traditional way to associate a specific user with a post is via a userid
column within posts. With such a model, you cant display posts without
retrieving (joining to) users. A possible alternative is simply to store the
name as well as the userid with each post. You could even do so with an
embedded document, like user: {id: ObjectId('Something'), name: 'Leto'}.
Yes, if you let users change their name, you may have to update each
document (which is one multi-update).
Example
 db.users.insert({name: 'leto, email: 'leto@dune.gov, addresses:
[{street: "229 W. 43rd St", city: "New York",
state:"NY",zip:"10036"},{street: "555 University", city: "Palo Alto",
state:"CA束,zip:"94107"}]})
 Comments and blogs example
When to use mongodb
 Flexible Schema
 Growing application
 Writes
 First, you have an option to send a write command and have it return
immediately without waiting for the write to be acknowledged.
 db.createCollection('logs', {capped: true ,size: 1048576})
 When our capped collection reaches its 1MB limit, old documents are
automatically purged.
 Durability
 MongoDB enables journaling by default, which allows fast recovery of the
server in case of a crash or abrupt power loss.
Continue 
 Full Text Search
 It supports fifteen languages with stemming and stop words.
 Transations eg. findAndModify, like $inc and $set.
 Data Processing
 feature-rich and different ways to group by (which is an understatement)
 Geospatial
 find documents that are $near a set of coordinates or $within a box or
circle.
 Tools
Aggregating data
 db.unicorns.aggregate([{$match: {weight:{$lt:600}}}, {$group:
{_id:'$gender', total:{$sum:1},
avgVamp:{$avg:'$vampires'}}},{$sort:{avgVamp:-1}} ])
 db.unicorns.aggregate([{$unwind:'$loves'},{$group: {_id:'$loves',
total:{$sum:1},unicorns:{$addToSet:'$name'}}},{$sort:{total:-
1}},{$limit:1} ])
 MapReduce
 MapReduce is a two-step approach to data processing. First you map, and
then you reduce
Performance and tools
 db.unicorns.ensureIndex({name: 1});
 db.unicorns.find().explain()
 db.unicorns.find({name: 'Pilot'}).explain()
 Replication
 MongoDB replication works in some ways similarly to how relational database replication works.
All production deployments should be replica sets, which consist of ideally three or more servers
that hold the same data.
 Sharding
 Sharding is an approach to scalability which partitions your data across multiple servers or
clusters.
* While replication can help performance somewhat (by isolating long running queries to
secondaries, and reducing latency for some other types of queries), its main purpose is to
provide high availability.
Continue 
 Stats
 You can obtain statistics on a database by typing db.stats().
 Profiler
 You enable the MongoDB profiler by executing: db.setProfilingLevel(2);
 With it enabled, we can run a command: db.unicorns.find({weight: {$gt:
600}});
 And then examine the profiler: db.system.profile.find()
 Backups and Restore
 mongodump --db learn --out backup
Ad

More Related Content

What's hot (20)

Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
Nate Abele
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
Murat akal
03. ElasticSearch : Data In, Data Out
03. ElasticSearch : Data In, Data Out03. ElasticSearch : Data In, Data Out
03. ElasticSearch : Data In, Data Out
OpenThink Labs
01 ElasticSearch : Getting Started
01 ElasticSearch : Getting Started01 ElasticSearch : Getting Started
01 ElasticSearch : Getting Started
OpenThink Labs
Back to Basics Webinar 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in Documents
MongoDB
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)""Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
MongoDB
Dev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesDev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best Practices
MongoDB
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World SettingJan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
George Ang
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
antoinegirbal
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB
Python Files
Python FilesPython Files
Python Files
Vikram Nandini
Indexing
IndexingIndexing
Indexing
Mike Dirolf
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Alex Bilbie
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
MongoDB
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
Mike Friedman
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real World
Mike Friedman
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social GraphSocialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
MongoDB
Database2
Database2Database2
Database2
Claudio Guidi
Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patterns
joergreichert
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
Nate Abele
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
Murat akal
03. ElasticSearch : Data In, Data Out
03. ElasticSearch : Data In, Data Out03. ElasticSearch : Data In, Data Out
03. ElasticSearch : Data In, Data Out
OpenThink Labs
01 ElasticSearch : Getting Started
01 ElasticSearch : Getting Started01 ElasticSearch : Getting Started
01 ElasticSearch : Getting Started
OpenThink Labs
Back to Basics Webinar 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in Documents
MongoDB
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)""Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
MongoDB
Dev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesDev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best Practices
MongoDB
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World SettingJan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
George Ang
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
antoinegirbal
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Alex Bilbie
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
MongoDB
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
Mike Friedman
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real World
Mike Friedman
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social GraphSocialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
MongoDB
Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patterns
joergreichert

Similar to Mongo db (20)

Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"
George Stathis
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
DATAVERSITY
Full metal mongo
Full metal mongoFull metal mongo
Full metal mongo
Israel Guti辿rrez
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
rogerbodamer
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
Eric Bottard
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
Israel Guti辿rrez
mongodb crud operations with detailed.ppt
mongodb crud operations with detailed.pptmongodb crud operations with detailed.ppt
mongodb crud operations with detailed.ppt
karthik761
Your Database Cannot Do this (well)
Your Database Cannot Do this (well)Your Database Cannot Do this (well)
Your Database Cannot Do this (well)
javier ramirez
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
MongoDB
Introduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopIntroduction to MongoDB and Workshop
Introduction to MongoDB and Workshop
AhmedabadJavaMeetup
Schema Design (Mongo Austin)
Schema Design (Mongo Austin)Schema Design (Mongo Austin)
Schema Design (Mongo Austin)
MongoDB
Elasticsearch - basics and beyond
Elasticsearch - basics and beyondElasticsearch - basics and beyond
Elasticsearch - basics and beyond
Ernesto Reig
MVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data libertyMVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data liberty
csmyth501
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data LibertyMVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
csmyth501
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
Henrik Ingo
Introduction to Graph Databases
Introduction to Graph DatabasesIntroduction to Graph Databases
Introduction to Graph Databases
Max De Marzi
Schema design
Schema designSchema design
Schema design
christkv
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
TO THE NEW | Technology
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
Karsten Dambekalns
Schema Design
Schema DesignSchema Design
Schema Design
MongoDB
Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"
George Stathis
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
DATAVERSITY
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
rogerbodamer
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
Eric Bottard
mongodb crud operations with detailed.ppt
mongodb crud operations with detailed.pptmongodb crud operations with detailed.ppt
mongodb crud operations with detailed.ppt
karthik761
Your Database Cannot Do this (well)
Your Database Cannot Do this (well)Your Database Cannot Do this (well)
Your Database Cannot Do this (well)
javier ramirez
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
MongoDB
Introduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopIntroduction to MongoDB and Workshop
Introduction to MongoDB and Workshop
AhmedabadJavaMeetup
Schema Design (Mongo Austin)
Schema Design (Mongo Austin)Schema Design (Mongo Austin)
Schema Design (Mongo Austin)
MongoDB
Elasticsearch - basics and beyond
Elasticsearch - basics and beyondElasticsearch - basics and beyond
Elasticsearch - basics and beyond
Ernesto Reig
MVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data libertyMVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data liberty
csmyth501
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data LibertyMVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
csmyth501
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
Henrik Ingo
Introduction to Graph Databases
Introduction to Graph DatabasesIntroduction to Graph Databases
Introduction to Graph Databases
Max De Marzi
Schema design
Schema designSchema design
Schema design
christkv
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
TO THE NEW | Technology
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
Karsten Dambekalns
Schema Design
Schema DesignSchema Design
Schema Design
MongoDB
Ad

Recently uploaded (20)

F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
The Elixir Developer - All Things Open
The Elixir Developer - All Things OpenThe Elixir Developer - All Things Open
The Elixir Developer - All Things Open
Carlo Gilmar Padilla Santana
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
Navigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdfNavigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdf
Applitools
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
Lionel Briand
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation  A Smarter Way to ScaleMaximizing ROI with Odoo Staff Augmentation  A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
SatishKumar2651
Building Apps for Good The Ethics of App Development
Building Apps for Good The Ethics of App DevelopmentBuilding Apps for Good The Ethics of App Development
Building Apps for Good The Ethics of App Development
Net-Craft.com
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
Effortless SMS Blasts from Salesforce with Message Blink No Tab Switching!
Effortless SMS Blasts from Salesforce with Message Blink  No Tab Switching!Effortless SMS Blasts from Salesforce with Message Blink  No Tab Switching!
Effortless SMS Blasts from Salesforce with Message Blink No Tab Switching!
Message Blink
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
Navigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdfNavigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdf
Applitools
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
Lionel Briand
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation  A Smarter Way to ScaleMaximizing ROI with Odoo Staff Augmentation  A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
SatishKumar2651
Building Apps for Good The Ethics of App Development
Building Apps for Good The Ethics of App DevelopmentBuilding Apps for Good The Ethics of App Development
Building Apps for Good The Ethics of App Development
Net-Craft.com
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
Effortless SMS Blasts from Salesforce with Message Blink No Tab Switching!
Effortless SMS Blasts from Salesforce with Message Blink  No Tab Switching!Effortless SMS Blasts from Salesforce with Message Blink  No Tab Switching!
Effortless SMS Blasts from Salesforce with Message Blink No Tab Switching!
Message Blink
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
Ad

Mongo db

  • 2. The Basics 1. MongoDB has the same concept of a database with which you are likely already familiar 2. A database can have zero or more collections. 3. Collections are made up of zero or more documents. 4. A document is made up of one or more fields 5. Indexes in MongoDB function mostly like their RDBMS counterparts. 6. Cursors are different than the other five concepts but they are important enough, and often overlooked
  • 3. Examples : 1 db.unicorns.insert({name: 'Aurora, gender: 'f', weight: 450}) db.unicorns.find() db.unicorns.insert({name: 'Horny',dob: new Date(1992,2,13,7,47), loves: ['carrot','papaya'],weight: 600,gender: 'm',vampires: 63}); The special $lt, $lte, $gt, $gte db.unicorns.find({gender: 'm',weight: {$gt: 700}}) db.unicorns.find({gender: {$ne: 'f'},weight: {$gte: 701}})
  • 4. Examples : 2 db.unicorns.find({vampires: {$exists: false}}) db.unicorns.find({loves: {$in:['apple','orange']}}) db.unicorns.find({gender: 'f, $or: [{loves: 'apple'},{weight: {$lt: 500}}]}) db.unicorns.find({_id: ObjectId("TheObjectId")})
  • 5. Updating Document db.unicorns.update({name: 'Roooooodles}, {weight: 590}) db.unicorns.update({weight: 590}, {$set: {name: 'Roooooodles',dob: new Date(1979, 7, 18, 18, 44), loves: ['apple'],gender: 'm',vampires: 99}}) db.unicorns.update({name: 'Roooooodles'},{$set: {weight: 590}}) db.unicorns.update({name: 'Pilot'},{$inc: {vampires: -2}}) db.unicorns.update({name: 'Aurora'},{$push: {loves: 'sugar'}})
  • 6. Upserts db.hits.update({page: 'unicorns}, {$inc: {hits: 1}}); db.hits.update({page: 'unicorns}, {$inc: {hits: 1}}, {upsert:true}); Multiple Updates db.unicorns.update({},{$set: {vaccinated: true }}); db.unicorns.update({},{$set: {vaccinated: true }},{multi:true});
  • 7. Find db.unicorns.find({}, {name: 1}); db.unicorns.find().sort({weight: -1}) db.unicorns.find().sort({name: 1,vampires: -1}) db.unicorns.find().sort({weight: -1}).limit(2).skip(1) db.unicorns.count({vampires: {$gt: 50}}) db.unicorns.find({vampires: {$gt: 50}}).count()
  • 8. Data Modeling No Joins The first and most fundamental difference that youll need to get comfortable with is MongoDBs lack of joins. joins are generally seen as non-scalable Embedded Documents db.employees.insert({_id: ObjectId("4d85c7039ab0fd70a117d734"),name: 'Ghanima',family: {mother: 'Chani',father: 'Paul',brother: ObjectId("4d85c7039ab0fd70a117d730")}})
  • 9. Denormalization Yet another alternative to using joins is to denormalize your data. Historically, denormalization was reserved for performance-sensitive code, or when data should be snapshotted (like in an audit log). However, with the ever growing popularity of NoSQL, many of which dont have joins, denormalization as part of normal modeling is becoming increasingly common. The traditional way to associate a specific user with a post is via a userid column within posts. With such a model, you cant display posts without retrieving (joining to) users. A possible alternative is simply to store the name as well as the userid with each post. You could even do so with an embedded document, like user: {id: ObjectId('Something'), name: 'Leto'}. Yes, if you let users change their name, you may have to update each document (which is one multi-update).
  • 10. Example db.users.insert({name: 'leto, email: 'leto@dune.gov, addresses: [{street: "229 W. 43rd St", city: "New York", state:"NY",zip:"10036"},{street: "555 University", city: "Palo Alto", state:"CA束,zip:"94107"}]}) Comments and blogs example
  • 11. When to use mongodb Flexible Schema Growing application Writes First, you have an option to send a write command and have it return immediately without waiting for the write to be acknowledged. db.createCollection('logs', {capped: true ,size: 1048576}) When our capped collection reaches its 1MB limit, old documents are automatically purged. Durability MongoDB enables journaling by default, which allows fast recovery of the server in case of a crash or abrupt power loss.
  • 12. Continue Full Text Search It supports fifteen languages with stemming and stop words. Transations eg. findAndModify, like $inc and $set. Data Processing feature-rich and different ways to group by (which is an understatement) Geospatial find documents that are $near a set of coordinates or $within a box or circle. Tools
  • 13. Aggregating data db.unicorns.aggregate([{$match: {weight:{$lt:600}}}, {$group: {_id:'$gender', total:{$sum:1}, avgVamp:{$avg:'$vampires'}}},{$sort:{avgVamp:-1}} ]) db.unicorns.aggregate([{$unwind:'$loves'},{$group: {_id:'$loves', total:{$sum:1},unicorns:{$addToSet:'$name'}}},{$sort:{total:- 1}},{$limit:1} ]) MapReduce MapReduce is a two-step approach to data processing. First you map, and then you reduce
  • 14. Performance and tools db.unicorns.ensureIndex({name: 1}); db.unicorns.find().explain() db.unicorns.find({name: 'Pilot'}).explain() Replication MongoDB replication works in some ways similarly to how relational database replication works. All production deployments should be replica sets, which consist of ideally three or more servers that hold the same data. Sharding Sharding is an approach to scalability which partitions your data across multiple servers or clusters. * While replication can help performance somewhat (by isolating long running queries to secondaries, and reducing latency for some other types of queries), its main purpose is to provide high availability.
  • 15. Continue Stats You can obtain statistics on a database by typing db.stats(). Profiler You enable the MongoDB profiler by executing: db.setProfilingLevel(2); With it enabled, we can run a command: db.unicorns.find({weight: {$gt: 600}}); And then examine the profiler: db.system.profile.find() Backups and Restore mongodump --db learn --out backup