Upload
algiers-tech-meetup
View
55
Download
0
Embed Size (px)
Citation preview
Introduction à Mongo DB
Aicha Khabil@Chichiboof
#NoSQL
Agenda
Why NoSQL What is Mongo DB Mongo DB Features
History
2010 Lots of traffic
SQL* *
SQL* *
Bigtable
Dynamo
NoSQL
#NoSQL
Johan Oskarsson
Caracteristics of NoSQL
DATA MODEL
Key-Value
2131101200
252544425
554245453
2456534534
Document{ name: ‘Mongo DB‘, signification: 'humongous', fr: ‘enorme', Release : ‘MongoV3,1'}
{ name: ‘NoSQL meeting ', date: ISODate("2016-10-08T09:00:00.382Z"), speakers: [ { name: ‘Speacker1' }, { name: ‘Speacker2’ } ]}
No schema
Column
A chaises
C lunettes
B Portes1 Choses
A Arabe
C Anglais
B Français2 Langues
A C# B JAVA3 Langages
Graph
Mongo DB
BSON DOCUMENT
FAST & PORTABLE
HorizontalScalability
Schema-less
Lexicus
RDBMS Mongo DBDatabase DatabaseTable CollectionTuple/Row DocumentColumn/attribute/Variable FieldTable Join Embedded DocumentsForeing Key ReferenceIndex IndexPrimary Key Object id _id
BSON Document{ id: ’doc1’, name: ‘Mongo DB‘, signification: 'humongous', fr: ‘enorme', Release : ‘MongoV3,1'}
{ _id:’doc2’, name: ‘NoSQL meeting ', date: ISODate("2016-10-08T09:00:00.382Z"), speakers: [ { name: ‘Speacker1' }, { name: ‘Speacker2’ } ], programme:{ name: ‘Mongo DB‘, signification: 'humongous', fr: ‘enorme', Release : ‘MongoV3,1'
}
}
Try It
https://www.tutorialspoint.com/mongodb_terminal_online.php
Aggregate data modal
Embedded docuement{ _id:ObjectId(‘xxxxxxxxxxxxxxxxx’), name: ‘NoSQL meeting ', date: ISODate("2016-10-08T09:00:00.382Z"), speakers: [ { name: ‘Speacker1' }, { name: ‘Speacker2’ } ], programme:{ _id:ObjectId(‘yyyyyyyyyyyy’), name: ‘Mongo DB‘, signification: 'humongous', fr: ‘enorme', Release : ‘MongoV3,1'
}
}
16 Mb
Use of reference{ _id:ObjectId(‘xxxxxxxxxxxxxxxxx’), name: ‘NoSQL meeting ', date: ISODate("2016-10-08T09:00:00.382Z"), speakers: [ { name: ‘Speacker1' }, { name: ‘Speacker2’ } ], programmeid:{ObjectId(‘yyyyyyyyyyyy’),}
}{
_id:ObjectId(‘yyyyyyyyyyyy’), name: ‘Mongo DB‘, signification: 'humongous', fr: ‘enorme', Release : ‘MongoV3,1'
}
DBRef{ _id:ObjectId(‘xxxxxxxxxxxxxxxxx’), name: ‘NoSQL meeting ', date: ISODate("2016-10-08T09:00:00.382Z"), speakers: [ { name: ‘Speacker1' }, { name: ‘Speacker2’ } ], programmeid: { "$ref" : "creators",
"$id" : ObjectId("5126bc054aed4daf9), "$db" : "users" }
}
{_id:ObjectId(‘5126bc054aed4daf9’), name: ‘Mongo DB‘, signification: 'humongous', fr: ‘enorme', Release : ‘MongoV3,1'
}
Collection : creatorsDb : Users
Request
Creat Read Update/Upsert Delete Map Reduce GridFs ( mongofiles.exe)
ObjectId Is 12-byte BSON type :
4 Bytesa 4-byte value the
Unix epoch
3-byte machine identifier
2-byte process id
3-byte counter, starting
Id = ObjectId()
Find document
db.<collection >. Find()
MongoDB cursor Skip() Pagin() Count() Limit() Next() Foreach() Etc
Find document by selector
db.<collection >. Find({_id : ObjectId (‘YYYYYYYYYYYY’)})
IndexesCreate Index on any field in the document// 1 means ascending, -1 means descending> db.posts.ensureIndex({‘author’: 1});
// unique index> db.posts.ensureIndex({<field>: 1},{unique:true});
MapReducedb.collection.mapReduce(
<mapfunction>, <reducefunction>, {
out: <collection>, query: <>, sort: <>, limit: <number>, finalize: <function>, scope: <>, jsMode: <boolean>, verbose: <boolean>
} )
var mapFunction1 = function() { emit(this.cust_id, this.price); }; var reduceFunction1 = function(keyCustId, valuesPrices) { return sum(valuesPrices); };
GridFs It is a specification for storing and
retrieving files that exceed the BSON-document size limite of 16 MB.
Mongofiles -d <db> put photo.jpg
Db.fs.files.find();
Mongo DB drivers PHP C# Python Ruby C++ Node js Etc ,,
MongoDB cloud providers
MongoLab MongoHQ AWS Joyent
MongoDB GUI Robomongo MongoBooster MongoDB Compass Etc
Replicat set
Primary
Secondary Secondary
DriverWrite
Update Update
Primary
Secondary Secondary
Heartbeats
Primary
Secondary Secondary
Heartbeats
Primary
Secondary Secondary
Primary ?
Primary
Primary Secondary
Secondary
Primary Secondary
Heartbeats
Sharding
Collection
Shard 1 Shard 2 Shard 3
COLLECTION
Shard 1P
DRIVER
Shard 1S
Shard 1S
Shard 2P
Shard 2S
Shard 2S
Shard 3P
Shard 3S
Shard 3S
Query router
Mongo DB V3.0
Mongo DB V3.0
Performance & Efficiency Gains,
New Storage Architecture
Thz
Thanks