SlideShare une entreprise Scribd logo
1  sur  101
Télécharger pour lire hors ligne
Material from mongodb.org licensed by MongoDB under Creative Commons. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.
halloween 
Party!
@andreabalducci 
halloween 
Party! 
#mhp14
intro
MongoDB 
MongoDB (from "humongous") is an 
open-source document database, and the 
leading NoSQL database. 
http://www.mongodb.org
Intro 
MongoDB is a document database that provides high performance, high availability, and easy scalability. 
• Document Database 
◦ Documents (objects) map nicely to programming language data types. 
◦ Embedded documents and arrays reduce need for joins. 
◦ Dynamic schema makes polymorphism easier. 
• High Performance 
◦ Embedding makes reads and writes fast. 
◦ Indexes can include keys from embedded documents and arrays. 
◦ Optional streaming writes (no acknowledgments). 
• High Availability 
◦ Replicated servers with automatic master failover. 
• Easy Scalability 
◦ Automatic sharding distributes collection data across machines. 
◦ Eventually-consistent reads can be distributed over replicated servers. 
http://www.mongodb.org/about/introduction/
Document Oriented Storage 
JSON-style documents with dynamic schemas offer 
simplicity and power.
Server 
Document Oriented Storage 
Database 
Collection 
Document 
{key : value}
Full Index Support 
Index on any attribute, just like you're used to.
Full Index Support 
Type Description 
Single Field 
A single field index only includes data from a single field of the 
documents in a collection. MongoDB supports single field indexes on 
fields at the top level of a document and on fields in sub-documents. 
Compound 
A compound index includes more than one field of the documents in a 
collection. 
Multikey 
A multikey index references an array and records a match if a query 
includes any value in the array. 
Geospatial 
Geospatial indexes support location-based searches on data that is 
stored as either GeoJSON objects or legacy coordinate pairs. 
Text Text indexes supports search of string content in documents. 
Hashed 
Hashed indexes maintain entries with hashes of the values of the 
indexed field.
Replication 
Replica sets provide redundancy and high availability, 
and are the basis for all production deployments.
Auto-Sharding 
Scale horizontally without compromising functionality
Querying 
Rich, document-based queries.
Fast In-Place Updates 
Atomic modifiers for contention-free performance.
Map / Reduce 
Flexible aggregation and data processing.
GridFS 
Store files of any size without complicating your stack
MMS 
Monitoring and backup designed for MongoDB.
Programs
Programs 
bsondump mongooplog 
mongo mongoperf 
mongod mongorestore 
mongodump mongos 
mongoexport mongosniff 
mongofiles mongostat 
mongoimport mongotop
mongo 
mongo is an interactive JavaScript shell interface to 
MongoDB, which provides a powerful interface for 
systems administrators as well as a way for 
developers to test queries and operations directly 
with the database. mongo also provides a fully 
functional JavaScript environment for use with a 
MongoDB. 
http://docs.mongodb.org/manual/reference/program/mongo/
mongo --nodb 
MongoDB shell version: 2.6.1 
> "m"+4+'n'+(5*2+2+2)+'abc Man'.substr(2)+'sion' 
> [1,2,3,4].forEach(function (n) { print(n); }) 
> exit
mongod 
mongod is the primary daemon process for the 
MongoDB system. It handles data requests, manages 
data format, and performs background management 
operations. 
http://docs.mongodb.org/manual/reference/program/mongod/
mongos 
mongos for “MongoDB Shard,” is a routing service 
for MongoDB shard configurations that processes 
queries from the application layer, and determines the 
location of this data in the sharded cluster, in order to 
complete these operations. From the perspective of 
the application, a mongos instance behaves 
identically to any other MongoDB instance. 
http://docs.mongodb.org/manual/reference/program/mongos/
mongodump 
mongodump is a utility for creating a binary export of 
the contents of a database. Consider using this utility 
as part an effective backup strategy. Use 
mongodump in conjunction with mongorestore to 
restore databases. 
mongodump can read data from either mongod or 
mongos instances, in addition to reading directly from 
MongoDB data files without an active mongod. 
http://docs.mongodb.org/manual/reference/program/mongodump/
bsondump 
The bsondump converts BSON files into human-readable 
formats, including JSON. For example, 
bsondump is useful for reading the output files 
generated by mongodump. 
http://docs.mongodb.org/manual/reference/program/bsondump/
mongorestore 
The mongorestore program writes data from a binary 
database dump created by mongodump to a 
MongoDB instance. mongorestore can create a new 
database or add data to an existing database. 
mongorestore can write data to either mongod or 
mongos instances, in addition to writing directly to 
MongoDB data files without an active mongod. 
http://docs.mongodb.org/manual/reference/program/mongorestore/
mongoexport 
mongoexport is a utility that produces a JSON or 
CSV export of data stored in a MongoDB instance. 
See the Import and Export MongoDB Data document 
for a more in depth usage overview, and the 
mongoimport document for more information 
regarding the mongoimport utility, which provides the 
inverse “importing” capability. 
http://docs.mongodb.org/manual/reference/program/mongoexport/
mongoimport 
The mongoimport tool provides a route to import 
content from a JSON, CSV, or TSV export created by 
mongoexport, or potentially, another third-party export 
tool. See the Import and Export MongoDB Data 
document for a more in depth usage overview, and the 
mongoexport document for more information regarding 
mongoexport, which provides the inverse “exporting” 
capability. 
http://docs.mongodb.org/manual/reference/program/mongoimport/
mongofiles 
The mongofiles utility makes it possible to manipulate 
files stored in your MongoDB instance in GridFS 
objects from the command line. It is particularly 
useful as it provides an interface between objects 
stored in your file system and GridFS. 
http://docs.mongodb.org/manual/reference/program/mongofiles/
mongooplog 
mongooplog is a simple tool that polls operations 
from the replication oplog of a remote server, and 
applies them to the local server. This capability 
supports certain classes of real-time migrations that 
require that the source server remain online and in 
operation throughout the migration process. 
http://docs.mongodb.org/manual/reference/program/mongooplog/
mongoperf 
mongoperf is a utility to check disk I/O performance 
independently of MongoDB. 
It times tests of random disk I/O and presents the 
results. You can use mongoperf for any case apart 
from MongoDB. 
http://docs.mongodb.org/manual/reference/program/mongoperf/
mongosniff 
mongosniff provides a low-level operation tracing/ 
sniffing view into database activity in real time. Think 
of mongosniff as a MongoDB-specific analogue of 
tcpdump for TCP/IP network traffic. Typically, 
mongosniff is most frequently used in driver 
development. 
http://docs.mongodb.org/manual/reference/program/mongosniff/
mongostat 
The mongostat utility provides a quick overview of 
the status of a currently running mongod or mongos 
instance. mongostat is functionally similar to the 
UNIX/Linux file system utility vmstat, but provides 
data regarding mongod and mongos instances. 
http://docs.mongodb.org/manual/reference/program/mongostat/
mongotop 
mongotop provides a method to track the amount of 
time a MongoDB instance spends reading and writing 
data. mongotop provides statistics on a per-collection 
level. By default, mongotop returns values 
every second. 
http://docs.mongodb.org/manual/reference/program/mongotop/
Json
JSON 
JSON (JavaScript Object Notation) is a lightweight data-interchange 
http://json.org 
format. 
It is easy for humans to read and write. 
It is easy for machines to parse and generate. 
It is based on a subset of the JavaScript Programming 
Language
JSON 
JSON is built on two structures: 
• A collection of name/value pairs. In various 
languages, this is realized as an object, record, 
struct, dictionary, hash table, keyed list, or 
associative array. 
• An ordered list of values. In most languages, this is 
realized as an array, vector, list, or sequence. 
These are universal data structures. 
http://json.org
Object 
{ 
"_id": "mongodb" 
} 
http://json.org
Array 
["2.4.5", "2.6.0", "2.6.1"] 
http://json.org
Value 
http://json.org
String 
http://json.org
Number 
http://json.org
{ 
"username": { 
"first": "Andrea", 
"last": "Balducci" 
}, 
"age": 40, 
"tags": ["mongodb", "elasticsearch", "eventsourcing", "ddd"], 
"groups": [{ 
"_id": 1, 
"name": "DevMarche" 
}, { 
"_id": 2, 
"name": "XPUG Marche" 
}] 
} 
json
http://jsbeautifier.org
BSON
BSON 
BSON is a binary serialization format used to store 
documents and make remote procedure calls in 
MongoDB. The BSON specification is located at 
bsonspec.org. 
http://docs.mongodb.org/manual/reference/bson-types/
BSON 
JSON can only represent a subset of the types 
supported by BSON. To preserve type information, 
MongoDB adds the following extensions to the JSON 
format: 
http://docs.mongodb.org/manual/reference/mongodb-extended-json/
Strict Mode 
Strict mode representations of BSON types conform 
to the JSON RFC. Any JSON parser can parse these 
strict mode representations as key/value pairs; 
however, only the MongoDB’s internal JSON parser 
also recognizes the type information conveyed by the 
format. 
http://docs.mongodb.org/manual/reference/mongodb-extended-json/
Shell mode 
The MongoDB’s internal JSON parser and the mongo 
shell can parse this mode. 
http://docs.mongodb.org/manual/reference/mongodb-extended-json/
BSON-Types 
Double String Object Array 
Binary Data Undefined Object Id Boolean 
Date Null RegExp JavaScript 
http://docs.mongodb.org/manual/reference/bson-types/ 
Symbol 
JavaScript 
(w/scope) 
Int32 Timestamp 
Int64 MinKey MaxKey
ObjectId 
ObjectId is a 12-byte BSON type, constructed using: 
• a 4-byte value representing the seconds since the 
Unix epoch, 
• a 3-byte machine identifier, 
• a 2-byte process id, and 
• a 3-byte counter, starting with a random value. 
http://docs.mongodb.org/manual/reference/object-id/
ObjectId 
The relationship between the order of ObjectId values 
and generation time is not strict within a single second. 
If multiple systems, or multiple processes or threads on 
a single system generate values, within a single second; 
ObjectId values do not represent a strict insertion order. 
Clock skew between clients can also result in non-strict 
ordering even for values, because client drivers 
generate ObjectId values, not the mongod process. 
http://docs.mongodb.org/manual/reference/object-id/
crud
bat = {/*oo*/} 
db.halloween.insert(bat) 
db.get 
db.getCollectionNames() 
db.halloween.f 
[ENT] 
[ENT] 
[TAB] 
[ENT] 
[TAB][ENT]
db.halloween.find() [ENT] 
[ENT] 
[ENT] 
bat 
db.halloween.insert
db.halloween.insert 
… 
if ( 
typeof(obj._id) == "undefined" && 
!Array.isArray(obj) 
){ 
var tmp = obj; // don't want to modify input 
obj = {_id: new ObjectId()}; 
for (var key in tmp){ 
obj[key] = tmp[key]; 
} 
} 
…
It’s the 
client baby
Read 
In MongoDB a query targets a specific collection of 
documents. Queries specify criteria, or conditions, 
that identify the documents that MongoDB returns to 
the clients. A query may include a projection that 
specifies the fields from the matching documents to 
return. You can optionally modify queries to impose 
limits, skips, and sort orders 
http://docs.mongodb.org/manual/core/crud-introduction/#query
Read 
In MongoDB, queries select documents from a single 
collection. 
http://docs.mongodb.org/manual/core/read-operations-introduction/
MongoDB - SQL 
http://docs.mongodb.org/manual/reference/sql-comparison/
Write 
A write operation is any operation that creates or 
modifies data in the MongoDB instance. In 
MongoDB, write operations target a single collection. 
All write operations in MongoDB are atomic on the 
level of a single document. 
There are three classes of write operations in 
MongoDB: insert, update, and remove. 
No insert, update, or remove can affect more than 
one document atomically. 
http://docs.mongodb.org/manual/core/write-operations-introduction/
Create 
Create operations add new documents to a 
collection. In MongoDB, the db.collection.insert() 
method perform create operations. 
http://docs.mongodb.org/manual/core/write-operations-introduction/
Update 
db.collection.update() and the db.collection.save() 
methods perform update operations. The 
db.collection.update() method can accept query 
criteria to determine which documents to update as 
well as an option to update multiple rows. 
http://docs.mongodb.org/manual/core/write-operations-introduction/
Delete 
Delete operations remove documents from a 
collection. In MongoDB, db.collection.remove() 
method performs delete operations. The 
db.collection.remove() method accepts a query 
criteria to determine which documents to remove. 
http://docs.mongodb.org/manual/core/write-operations-introduction/
tags = []; 
[1,2,3,4].forEach(function(num){ 
tags.push(''+num); 
db.halloween.insert({ 
num: NumberInt(num), 
tags:tags 
}) 
}) 
Sample Data
Find All 
db.halloween.find({ 
})
db.halloween.find({ 
tags:'2' 
}) 
Array filter
db.halloween.find({ 
tags:'2', 
num: 2 
}) 
And
tags = ‘1’ AND tags=‘3’ 
db.halloween.find({ 
tags:'1', 
tags:'3' 
})
1,2,3…..3,2,1
tags = ‘1’ AND tags=‘3’ 
db.halloween.find({ 
tags:'1', 
tags:'3' 
})
tags = ‘1’ AND tags=‘3’ 
db.halloween.find({ 
tags:'3', 
tags:'1' 
})
JSON! 
db.halloween.find({ 
tags:'3', 
tags:'1' 
}) 
/kəˈpʊt/
Write Isolation 
The modification of a single document is always 
atomic, even if the write operation modifies multiple 
sub-documents within that document. 
For write operations that modify multiple documents, 
the operation as a whole is not atomic, and other 
operations may interleave. 
http://docs.mongodb.org/manual/core/write-operations-introduction/
Write-Concern 
Write concern describes the guarantee that 
MongoDB provides when reporting on the success of 
a write operation. The strength of the write concerns 
determine the level of guarantee. 
Fast Slow 
Unacknowledged Acknowledged Journaled Replica Acknowledged 
Weak Strong 
http://docs.mongodb.org/manual/core/write-concern/
Unacknowledged 
With an unacknowledged write concern, MongoDB 
does not acknowledge the receipt of write 
operations. Unacknowledged is similar to errors 
ignored; however, drivers will attempt to receive and 
handle network errors when possible. The driver’s 
ability to detect network errors depends on the 
system’s networking configuration. 
http://docs.mongodb.org/manual/core/write-concern/
Unacknowledged 
http://docs.mongodb.org/manual/core/write-concern/
Acknowledged 
With a receipt acknowledged write concern, the 
mongod confirms the receipt of the write operation. 
Acknowledged write concern allows clients to catch 
network, duplicate key, and other errors. 
http://docs.mongodb.org/manual/core/write-concern/
Acknowledged 
http://docs.mongodb.org/manual/core/write-concern/
Journaled 
With a journaled write concern, the MongoDB 
acknowledges the write operation only after 
committing the data to the journal. This write concern 
ensures that MongoDB can recover the data 
following a shutdown or power interruption. 
http://docs.mongodb.org/manual/core/write-concern/
Journaled 
http://docs.mongodb.org/manual/core/write-concern/
Replica Acknowledged 
Replica sets present additional considerations with 
regards to write concern.. The default write concern 
only requires acknowledgement from the primary. 
With replica acknowledged write concern, you can 
guarantee that the write operation propagates to 
additional members of the replica set 
http://docs.mongodb.org/manual/core/write-concern/
Replica Acknowledged 
http://docs.mongodb.org/manual/core/write-concern/
Read Isolation 
MongoDB allows clients to read documents inserted 
or modified before it commits these modifications to 
disk, regardless of write concern level or journaling 
configuration. 
http://docs.mongodb.org/manual/core/write-concern/
Read Isolation 
• For systems with multiple concurrent readers and 
writers, MongoDB will allow clients to read the 
results of a write operation before the write 
operation returns. 
• If the mongod terminates before the journal 
commits, even if a write returns successfully, 
queries may have read data that will not exist after 
the mongod restarts. 
http://docs.mongodb.org/manual/core/write-concern/
Durability 
Data is flushed every 60 seconds. 
Journal every 100ms if on the same volume of the data, 
every 30ms if on a different disk 
Journaled write concern set the journaling interval to 1/3
demo 
Download and install http://robomongo.org 
db.tmp.insert({ x : 1 }); 
db.runCommand({ 
"getLastError" : 1, 
"j" : true 
}); 
db.serverStatus();
Aggregation 
framework
Aggregation 
Aggregations are operations that process data 
records and return computed results. MongoDB 
provides a rich set of aggregation operations that 
examine and perform calculations on the data sets. 
Running data aggregation on the mongod instance 
simplifies application code and limits resource 
requirements. 
http://docs.mongodb.org/manual/core/aggregation-introduction/
Aggregation 
Like queries, aggregation operations in MongoDB use 
collections of documents as an input and return results 
in the form of one or more documents. 
http://docs.mongodb.org/manual/core/aggregation-introduction/
Data Processing Pipeline 
http://docs.mongodb.org/manual/core/aggregation-introduction/
Operator Reference 
http://docs.mongodb.org/manual/reference/operator/ 
aggregation/#aggregation-pipeline-operator-reference
Trick or treat 
?
http://tinyurl.com/mohapa
@andreabalducci 
thanks! 
#mhp14

Contenu connexe

Tendances

MongoDB Knowledge Shareing
MongoDB Knowledge ShareingMongoDB Knowledge Shareing
MongoDB Knowledge Shareing
Philip Zhong
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
Kai Zhao
 
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
Alex Nguyen
 
Building Spring Data with MongoDB
Building Spring Data with MongoDBBuilding Spring Data with MongoDB
Building Spring Data with MongoDB
MongoDB
 

Tendances (20)

Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node js
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
MongoDB Knowledge Shareing
MongoDB Knowledge ShareingMongoDB Knowledge Shareing
MongoDB Knowledge Shareing
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongodb Introduction
Mongodb IntroductionMongodb Introduction
Mongodb Introduction
 
Mdb dn 2016_08_tools
Mdb dn 2016_08_toolsMdb dn 2016_08_tools
Mdb dn 2016_08_tools
 
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDBMongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
MongoDB Days Silicon Valley: Introducing MongoDB 3.2
MongoDB Days Silicon Valley: Introducing MongoDB 3.2MongoDB Days Silicon Valley: Introducing MongoDB 3.2
MongoDB Days Silicon Valley: Introducing MongoDB 3.2
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
Mongo db present
Mongo db presentMongo db present
Mongo db present
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
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
 
Building Spring Data with MongoDB
Building Spring Data with MongoDBBuilding Spring Data with MongoDB
Building Spring Data with MongoDB
 

En vedette

Got index
Got indexGot index
Got index
MongoDB
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
MongoDB
 

En vedette (6)

Got index
Got indexGot index
Got index
 
MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.
 
Building a Scalable and Modern Infrastructure at CARFAX
Building a Scalable and Modern Infrastructure at CARFAXBuilding a Scalable and Modern Infrastructure at CARFAX
Building a Scalable and Modern Infrastructure at CARFAX
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
 
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...
 
Webinar: How Penton Uses MongoDB As an Analytics Platform within their Drupal...
Webinar: How Penton Uses MongoDB As an Analytics Platform within their Drupal...Webinar: How Penton Uses MongoDB As an Analytics Platform within their Drupal...
Webinar: How Penton Uses MongoDB As an Analytics Platform within their Drupal...
 

Similaire à Mongo db halloween party

upload.txt
upload.txtupload.txt
upload.txt
IshNexus
 

Similaire à Mongo db halloween party (20)

MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB Tutorials
 
MongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & ExecutionMongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & Execution
 
MongoDB
MongoDBMongoDB
MongoDB
 
edit and approve 2
edit and approve 2edit and approve 2
edit and approve 2
 
upload.txt
upload.txtupload.txt
upload.txt
 
Mongo db transcript
Mongo db transcriptMongo db transcript
Mongo db transcript
 
Top MongoDB interview Questions and Answers
Top MongoDB interview Questions and AnswersTop MongoDB interview Questions and Answers
Top MongoDB interview Questions and Answers
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
 
upload.txt
upload.txtupload.txt
upload.txt
 
upload.txt
upload.txtupload.txt
upload.txt
 
Analytical data processing
Analytical data processingAnalytical data processing
Analytical data processing
 
Mongo db and hadoop driving business insights - final
Mongo db and hadoop   driving business insights - finalMongo db and hadoop   driving business insights - final
Mongo db and hadoop driving business insights - final
 
upload.txt
upload.txtupload.txt
upload.txt
 
uploaded at 10:56
uploaded at 10:56uploaded at 10:56
uploaded at 10:56
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
 
Klevis Mino: MongoDB
Klevis Mino: MongoDBKlevis Mino: MongoDB
Klevis Mino: MongoDB
 
Introduction to MongoDB (Webinar Jan 2011)
Introduction to MongoDB (Webinar Jan 2011)Introduction to MongoDB (Webinar Jan 2011)
Introduction to MongoDB (Webinar Jan 2011)
 
Elasticsearch vs MongoDB comparison
Elasticsearch vs MongoDB comparisonElasticsearch vs MongoDB comparison
Elasticsearch vs MongoDB comparison
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 

Plus de Andrea Balducci

Plus de Andrea Balducci (17)

Agile Industry 4.0 - IoT Day 2019
Agile Industry 4.0 - IoT Day 2019Agile Industry 4.0 - IoT Day 2019
Agile Industry 4.0 - IoT Day 2019
 
Inception
InceptionInception
Inception
 
Stranger Streams | NStore @ DevMarche
Stranger Streams | NStore @ DevMarcheStranger Streams | NStore @ DevMarche
Stranger Streams | NStore @ DevMarche
 
Event based modelling and prototyping
Event based modelling and prototypingEvent based modelling and prototyping
Event based modelling and prototyping
 
Storage dei dati con MongoDB
Storage dei dati con MongoDBStorage dei dati con MongoDB
Storage dei dati con MongoDB
 
Italian Agile Days 2016 - Modellathon
Italian Agile Days 2016 - ModellathonItalian Agile Days 2016 - Modellathon
Italian Agile Days 2016 - Modellathon
 
Open domus 2016
Open domus 2016Open domus 2016
Open domus 2016
 
Oktober webfest
Oktober webfestOktober webfest
Oktober webfest
 
TypeScript intro / mobile dev camp
TypeScript intro / mobile dev campTypeScript intro / mobile dev camp
TypeScript intro / mobile dev camp
 
Typescript intro
Typescript introTypescript intro
Typescript intro
 
Alam aeki 2015
Alam aeki 2015Alam aeki 2015
Alam aeki 2015
 
[Alam aeki] Guida illustrata alla modellazione di un dominio con Event Sourci...
[Alam aeki] Guida illustrata alla modellazione di un dominio con Event Sourci...[Alam aeki] Guida illustrata alla modellazione di un dominio con Event Sourci...
[Alam aeki] Guida illustrata alla modellazione di un dominio con Event Sourci...
 
Event Sourcing con NEventStore
Event Sourcing con NEventStoreEvent Sourcing con NEventStore
Event Sourcing con NEventStore
 
Intel AppUp Day Bologna
Intel AppUp Day BolognaIntel AppUp Day Bologna
Intel AppUp Day Bologna
 
Asp.Net MVC 2 :: VS 2010 Community Tour
Asp.Net MVC 2 :: VS 2010 Community TourAsp.Net MVC 2 :: VS 2010 Community Tour
Asp.Net MVC 2 :: VS 2010 Community Tour
 
Introduzione ai framework ioc
Introduzione ai framework iocIntroduzione ai framework ioc
Introduzione ai framework ioc
 
jQuery Ecosystem
jQuery EcosystemjQuery Ecosystem
jQuery Ecosystem
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Dernier (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Mongo db halloween party

  • 1. Material from mongodb.org licensed by MongoDB under Creative Commons. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.
  • 5. MongoDB MongoDB (from "humongous") is an open-source document database, and the leading NoSQL database. http://www.mongodb.org
  • 6. Intro MongoDB is a document database that provides high performance, high availability, and easy scalability. • Document Database ◦ Documents (objects) map nicely to programming language data types. ◦ Embedded documents and arrays reduce need for joins. ◦ Dynamic schema makes polymorphism easier. • High Performance ◦ Embedding makes reads and writes fast. ◦ Indexes can include keys from embedded documents and arrays. ◦ Optional streaming writes (no acknowledgments). • High Availability ◦ Replicated servers with automatic master failover. • Easy Scalability ◦ Automatic sharding distributes collection data across machines. ◦ Eventually-consistent reads can be distributed over replicated servers. http://www.mongodb.org/about/introduction/
  • 7. Document Oriented Storage JSON-style documents with dynamic schemas offer simplicity and power.
  • 8. Server Document Oriented Storage Database Collection Document {key : value}
  • 9. Full Index Support Index on any attribute, just like you're used to.
  • 10. Full Index Support Type Description Single Field A single field index only includes data from a single field of the documents in a collection. MongoDB supports single field indexes on fields at the top level of a document and on fields in sub-documents. Compound A compound index includes more than one field of the documents in a collection. Multikey A multikey index references an array and records a match if a query includes any value in the array. Geospatial Geospatial indexes support location-based searches on data that is stored as either GeoJSON objects or legacy coordinate pairs. Text Text indexes supports search of string content in documents. Hashed Hashed indexes maintain entries with hashes of the values of the indexed field.
  • 11. Replication Replica sets provide redundancy and high availability, and are the basis for all production deployments.
  • 12. Auto-Sharding Scale horizontally without compromising functionality
  • 14. Fast In-Place Updates Atomic modifiers for contention-free performance.
  • 15. Map / Reduce Flexible aggregation and data processing.
  • 16. GridFS Store files of any size without complicating your stack
  • 17. MMS Monitoring and backup designed for MongoDB.
  • 19. Programs bsondump mongooplog mongo mongoperf mongod mongorestore mongodump mongos mongoexport mongosniff mongofiles mongostat mongoimport mongotop
  • 20. mongo mongo is an interactive JavaScript shell interface to MongoDB, which provides a powerful interface for systems administrators as well as a way for developers to test queries and operations directly with the database. mongo also provides a fully functional JavaScript environment for use with a MongoDB. http://docs.mongodb.org/manual/reference/program/mongo/
  • 21. mongo --nodb MongoDB shell version: 2.6.1 > "m"+4+'n'+(5*2+2+2)+'abc Man'.substr(2)+'sion' > [1,2,3,4].forEach(function (n) { print(n); }) > exit
  • 22. mongod mongod is the primary daemon process for the MongoDB system. It handles data requests, manages data format, and performs background management operations. http://docs.mongodb.org/manual/reference/program/mongod/
  • 23. mongos mongos for “MongoDB Shard,” is a routing service for MongoDB shard configurations that processes queries from the application layer, and determines the location of this data in the sharded cluster, in order to complete these operations. From the perspective of the application, a mongos instance behaves identically to any other MongoDB instance. http://docs.mongodb.org/manual/reference/program/mongos/
  • 24. mongodump mongodump is a utility for creating a binary export of the contents of a database. Consider using this utility as part an effective backup strategy. Use mongodump in conjunction with mongorestore to restore databases. mongodump can read data from either mongod or mongos instances, in addition to reading directly from MongoDB data files without an active mongod. http://docs.mongodb.org/manual/reference/program/mongodump/
  • 25. bsondump The bsondump converts BSON files into human-readable formats, including JSON. For example, bsondump is useful for reading the output files generated by mongodump. http://docs.mongodb.org/manual/reference/program/bsondump/
  • 26. mongorestore The mongorestore program writes data from a binary database dump created by mongodump to a MongoDB instance. mongorestore can create a new database or add data to an existing database. mongorestore can write data to either mongod or mongos instances, in addition to writing directly to MongoDB data files without an active mongod. http://docs.mongodb.org/manual/reference/program/mongorestore/
  • 27. mongoexport mongoexport is a utility that produces a JSON or CSV export of data stored in a MongoDB instance. See the Import and Export MongoDB Data document for a more in depth usage overview, and the mongoimport document for more information regarding the mongoimport utility, which provides the inverse “importing” capability. http://docs.mongodb.org/manual/reference/program/mongoexport/
  • 28. mongoimport The mongoimport tool provides a route to import content from a JSON, CSV, or TSV export created by mongoexport, or potentially, another third-party export tool. See the Import and Export MongoDB Data document for a more in depth usage overview, and the mongoexport document for more information regarding mongoexport, which provides the inverse “exporting” capability. http://docs.mongodb.org/manual/reference/program/mongoimport/
  • 29. mongofiles The mongofiles utility makes it possible to manipulate files stored in your MongoDB instance in GridFS objects from the command line. It is particularly useful as it provides an interface between objects stored in your file system and GridFS. http://docs.mongodb.org/manual/reference/program/mongofiles/
  • 30. mongooplog mongooplog is a simple tool that polls operations from the replication oplog of a remote server, and applies them to the local server. This capability supports certain classes of real-time migrations that require that the source server remain online and in operation throughout the migration process. http://docs.mongodb.org/manual/reference/program/mongooplog/
  • 31. mongoperf mongoperf is a utility to check disk I/O performance independently of MongoDB. It times tests of random disk I/O and presents the results. You can use mongoperf for any case apart from MongoDB. http://docs.mongodb.org/manual/reference/program/mongoperf/
  • 32. mongosniff mongosniff provides a low-level operation tracing/ sniffing view into database activity in real time. Think of mongosniff as a MongoDB-specific analogue of tcpdump for TCP/IP network traffic. Typically, mongosniff is most frequently used in driver development. http://docs.mongodb.org/manual/reference/program/mongosniff/
  • 33. mongostat The mongostat utility provides a quick overview of the status of a currently running mongod or mongos instance. mongostat is functionally similar to the UNIX/Linux file system utility vmstat, but provides data regarding mongod and mongos instances. http://docs.mongodb.org/manual/reference/program/mongostat/
  • 34. mongotop mongotop provides a method to track the amount of time a MongoDB instance spends reading and writing data. mongotop provides statistics on a per-collection level. By default, mongotop returns values every second. http://docs.mongodb.org/manual/reference/program/mongotop/
  • 35. Json
  • 36. JSON JSON (JavaScript Object Notation) is a lightweight data-interchange http://json.org format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language
  • 37. JSON JSON is built on two structures: • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array. • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence. These are universal data structures. http://json.org
  • 38. Object { "_id": "mongodb" } http://json.org
  • 39. Array ["2.4.5", "2.6.0", "2.6.1"] http://json.org
  • 43. { "username": { "first": "Andrea", "last": "Balducci" }, "age": 40, "tags": ["mongodb", "elasticsearch", "eventsourcing", "ddd"], "groups": [{ "_id": 1, "name": "DevMarche" }, { "_id": 2, "name": "XPUG Marche" }] } json
  • 44.
  • 46. BSON
  • 47. BSON BSON is a binary serialization format used to store documents and make remote procedure calls in MongoDB. The BSON specification is located at bsonspec.org. http://docs.mongodb.org/manual/reference/bson-types/
  • 48. BSON JSON can only represent a subset of the types supported by BSON. To preserve type information, MongoDB adds the following extensions to the JSON format: http://docs.mongodb.org/manual/reference/mongodb-extended-json/
  • 49. Strict Mode Strict mode representations of BSON types conform to the JSON RFC. Any JSON parser can parse these strict mode representations as key/value pairs; however, only the MongoDB’s internal JSON parser also recognizes the type information conveyed by the format. http://docs.mongodb.org/manual/reference/mongodb-extended-json/
  • 50. Shell mode The MongoDB’s internal JSON parser and the mongo shell can parse this mode. http://docs.mongodb.org/manual/reference/mongodb-extended-json/
  • 51. BSON-Types Double String Object Array Binary Data Undefined Object Id Boolean Date Null RegExp JavaScript http://docs.mongodb.org/manual/reference/bson-types/ Symbol JavaScript (w/scope) Int32 Timestamp Int64 MinKey MaxKey
  • 52.
  • 53.
  • 54. ObjectId ObjectId is a 12-byte BSON type, constructed using: • a 4-byte value representing the seconds since the Unix epoch, • a 3-byte machine identifier, • a 2-byte process id, and • a 3-byte counter, starting with a random value. http://docs.mongodb.org/manual/reference/object-id/
  • 55. ObjectId The relationship between the order of ObjectId values and generation time is not strict within a single second. If multiple systems, or multiple processes or threads on a single system generate values, within a single second; ObjectId values do not represent a strict insertion order. Clock skew between clients can also result in non-strict ordering even for values, because client drivers generate ObjectId values, not the mongod process. http://docs.mongodb.org/manual/reference/object-id/
  • 56. crud
  • 57. bat = {/*oo*/} db.halloween.insert(bat) db.get db.getCollectionNames() db.halloween.f [ENT] [ENT] [TAB] [ENT] [TAB][ENT]
  • 58.
  • 59. db.halloween.find() [ENT] [ENT] [ENT] bat db.halloween.insert
  • 60. db.halloween.insert … if ( typeof(obj._id) == "undefined" && !Array.isArray(obj) ){ var tmp = obj; // don't want to modify input obj = {_id: new ObjectId()}; for (var key in tmp){ obj[key] = tmp[key]; } } …
  • 62. Read In MongoDB a query targets a specific collection of documents. Queries specify criteria, or conditions, that identify the documents that MongoDB returns to the clients. A query may include a projection that specifies the fields from the matching documents to return. You can optionally modify queries to impose limits, skips, and sort orders http://docs.mongodb.org/manual/core/crud-introduction/#query
  • 63. Read In MongoDB, queries select documents from a single collection. http://docs.mongodb.org/manual/core/read-operations-introduction/
  • 64. MongoDB - SQL http://docs.mongodb.org/manual/reference/sql-comparison/
  • 65. Write A write operation is any operation that creates or modifies data in the MongoDB instance. In MongoDB, write operations target a single collection. All write operations in MongoDB are atomic on the level of a single document. There are three classes of write operations in MongoDB: insert, update, and remove. No insert, update, or remove can affect more than one document atomically. http://docs.mongodb.org/manual/core/write-operations-introduction/
  • 66. Create Create operations add new documents to a collection. In MongoDB, the db.collection.insert() method perform create operations. http://docs.mongodb.org/manual/core/write-operations-introduction/
  • 67. Update db.collection.update() and the db.collection.save() methods perform update operations. The db.collection.update() method can accept query criteria to determine which documents to update as well as an option to update multiple rows. http://docs.mongodb.org/manual/core/write-operations-introduction/
  • 68. Delete Delete operations remove documents from a collection. In MongoDB, db.collection.remove() method performs delete operations. The db.collection.remove() method accepts a query criteria to determine which documents to remove. http://docs.mongodb.org/manual/core/write-operations-introduction/
  • 69. tags = []; [1,2,3,4].forEach(function(num){ tags.push(''+num); db.halloween.insert({ num: NumberInt(num), tags:tags }) }) Sample Data
  • 73. tags = ‘1’ AND tags=‘3’ db.halloween.find({ tags:'1', tags:'3' })
  • 75. tags = ‘1’ AND tags=‘3’ db.halloween.find({ tags:'1', tags:'3' })
  • 76. tags = ‘1’ AND tags=‘3’ db.halloween.find({ tags:'3', tags:'1' })
  • 77. JSON! db.halloween.find({ tags:'3', tags:'1' }) /kəˈpʊt/
  • 78. Write Isolation The modification of a single document is always atomic, even if the write operation modifies multiple sub-documents within that document. For write operations that modify multiple documents, the operation as a whole is not atomic, and other operations may interleave. http://docs.mongodb.org/manual/core/write-operations-introduction/
  • 79. Write-Concern Write concern describes the guarantee that MongoDB provides when reporting on the success of a write operation. The strength of the write concerns determine the level of guarantee. Fast Slow Unacknowledged Acknowledged Journaled Replica Acknowledged Weak Strong http://docs.mongodb.org/manual/core/write-concern/
  • 80. Unacknowledged With an unacknowledged write concern, MongoDB does not acknowledge the receipt of write operations. Unacknowledged is similar to errors ignored; however, drivers will attempt to receive and handle network errors when possible. The driver’s ability to detect network errors depends on the system’s networking configuration. http://docs.mongodb.org/manual/core/write-concern/
  • 82. Acknowledged With a receipt acknowledged write concern, the mongod confirms the receipt of the write operation. Acknowledged write concern allows clients to catch network, duplicate key, and other errors. http://docs.mongodb.org/manual/core/write-concern/
  • 84. Journaled With a journaled write concern, the MongoDB acknowledges the write operation only after committing the data to the journal. This write concern ensures that MongoDB can recover the data following a shutdown or power interruption. http://docs.mongodb.org/manual/core/write-concern/
  • 86. Replica Acknowledged Replica sets present additional considerations with regards to write concern.. The default write concern only requires acknowledgement from the primary. With replica acknowledged write concern, you can guarantee that the write operation propagates to additional members of the replica set http://docs.mongodb.org/manual/core/write-concern/
  • 88. Read Isolation MongoDB allows clients to read documents inserted or modified before it commits these modifications to disk, regardless of write concern level or journaling configuration. http://docs.mongodb.org/manual/core/write-concern/
  • 89. Read Isolation • For systems with multiple concurrent readers and writers, MongoDB will allow clients to read the results of a write operation before the write operation returns. • If the mongod terminates before the journal commits, even if a write returns successfully, queries may have read data that will not exist after the mongod restarts. http://docs.mongodb.org/manual/core/write-concern/
  • 90. Durability Data is flushed every 60 seconds. Journal every 100ms if on the same volume of the data, every 30ms if on a different disk Journaled write concern set the journaling interval to 1/3
  • 91. demo Download and install http://robomongo.org db.tmp.insert({ x : 1 }); db.runCommand({ "getLastError" : 1, "j" : true }); db.serverStatus();
  • 93. Aggregation Aggregations are operations that process data records and return computed results. MongoDB provides a rich set of aggregation operations that examine and perform calculations on the data sets. Running data aggregation on the mongod instance simplifies application code and limits resource requirements. http://docs.mongodb.org/manual/core/aggregation-introduction/
  • 94. Aggregation Like queries, aggregation operations in MongoDB use collections of documents as an input and return results in the form of one or more documents. http://docs.mongodb.org/manual/core/aggregation-introduction/
  • 95. Data Processing Pipeline http://docs.mongodb.org/manual/core/aggregation-introduction/
  • 96. Operator Reference http://docs.mongodb.org/manual/reference/operator/ aggregation/#aggregation-pipeline-operator-reference
  • 99.
  • 100.