54
Introduction à Mongo DB Aicha Khabil @ Chichiboof [email protected] #NoSQL

Introduction to MongoDB

Embed Size (px)

Citation preview

Page 1: Introduction to MongoDB

Introduction à Mongo DB

Aicha Khabil@Chichiboof

[email protected]

#NoSQL

Page 2: Introduction to MongoDB

Agenda

Why NoSQL What is Mongo DB Mongo DB Features

Page 3: Introduction to MongoDB

History

Page 4: Introduction to MongoDB

2010 Lots of traffic

Page 5: Introduction to MongoDB
Page 6: Introduction to MongoDB
Page 7: Introduction to MongoDB

SQL* *

SQL* *

Page 8: Introduction to MongoDB

Bigtable

Dynamo

Page 9: Introduction to MongoDB

NoSQL

Page 10: Introduction to MongoDB

#NoSQL

Johan Oskarsson

Page 11: Introduction to MongoDB
Page 12: Introduction to MongoDB

Caracteristics of NoSQL

Page 13: Introduction to MongoDB

DATA MODEL

Page 14: Introduction to MongoDB
Page 15: Introduction to MongoDB
Page 16: Introduction to MongoDB

Key-Value

2131101200

252544425

554245453

2456534534

Page 17: Introduction to MongoDB

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

Page 18: Introduction to MongoDB

Column

A chaises

C lunettes

B Portes1 Choses

A Arabe

C Anglais

B Français2 Langues

A C# B JAVA3 Langages

Page 19: Introduction to MongoDB

Graph

Page 20: Introduction to MongoDB
Page 21: Introduction to MongoDB

Mongo DB

BSON DOCUMENT

FAST & PORTABLE

HorizontalScalability

Schema-less

Page 22: Introduction to MongoDB

Lexicus

RDBMS Mongo DBDatabase DatabaseTable CollectionTuple/Row DocumentColumn/attribute/Variable FieldTable Join Embedded DocumentsForeing Key ReferenceIndex IndexPrimary Key Object id _id

Page 23: Introduction to MongoDB

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'

}

}

Page 24: Introduction to MongoDB

Try It

https://www.tutorialspoint.com/mongodb_terminal_online.php

Page 25: Introduction to MongoDB

Aggregate data modal

Page 26: Introduction to MongoDB

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

Page 27: Introduction to MongoDB

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'

}

Page 28: Introduction to MongoDB

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

Page 29: Introduction to MongoDB

Request

Creat Read Update/Upsert Delete Map Reduce GridFs ( mongofiles.exe)

Page 30: Introduction to MongoDB

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()

Page 31: Introduction to MongoDB

Find document

db.<collection >. Find()

Page 32: Introduction to MongoDB

MongoDB cursor Skip() Pagin() Count() Limit() Next() Foreach() Etc

Page 33: Introduction to MongoDB

Find document by selector

db.<collection >. Find({_id : ObjectId (‘YYYYYYYYYYYY’)})

Page 34: Introduction to MongoDB

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});

Page 35: Introduction to MongoDB

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); };

Page 36: Introduction to MongoDB
Page 37: Introduction to MongoDB

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();

Page 38: Introduction to MongoDB

Mongo DB drivers PHP C# Python Ruby C++ Node js Etc ,,

Page 39: Introduction to MongoDB

MongoDB cloud providers

MongoLab MongoHQ AWS Joyent

Page 40: Introduction to MongoDB

MongoDB GUI Robomongo MongoBooster MongoDB Compass Etc

Page 41: Introduction to MongoDB

Replicat set

Page 42: Introduction to MongoDB

Primary

Secondary Secondary

DriverWrite

Update Update

Page 43: Introduction to MongoDB

Primary

Secondary Secondary

Heartbeats

Page 44: Introduction to MongoDB

Primary

Secondary Secondary

Heartbeats

Page 45: Introduction to MongoDB

Primary

Secondary Secondary

Primary ?

Page 46: Introduction to MongoDB

Primary

Primary Secondary

Page 47: Introduction to MongoDB

Secondary

Primary Secondary

Heartbeats

Page 48: Introduction to MongoDB

Sharding

Page 49: Introduction to MongoDB

Collection

Page 50: Introduction to MongoDB

Shard 1 Shard 2 Shard 3

COLLECTION

Page 51: Introduction to MongoDB

Shard 1P

DRIVER

Shard 1S

Shard 1S

Shard 2P

Shard 2S

Shard 2S

Shard 3P

Shard 3S

Shard 3S

Query router

Page 52: Introduction to MongoDB

Mongo DB V3.0

Page 53: Introduction to MongoDB

Mongo DB V3.0

Performance & Efficiency Gains,

New Storage Architecture

Page 54: Introduction to MongoDB

Thz

Thanks