mongodb - ekino php

Download MongoDB - Ekino PHP

If you can't read please download the document

Upload: florent-denis

Post on 16-Apr-2017

8.849 views

Category:

Technology


1 download

TRANSCRIPT

MongoDB Partie 1

What the no-sql?

Introduction

Qu'est-ce que le no-sql?Tout ce qui n'est pas SQLLe no-sql a toujours exist

Introduction

PHPCRCl-valeurOrient columnsOrient document

MongoDB

MongoDB InfosMongoDB ("humongous")10gen2007 start project2009 open sourceC++Licence: GNU AGPL v3.0 (drivers: Apache licence)Easy, scalability and Big DATAGeolocalisation

Data

MongoDB MySQL

SGDB > databases > collections > documents

SGDB > databases > tables > lignes

No structureDynamic schema

StructureStatic schema

Pas de transaction

Terminologie :Table = Collection,Ligne = Document,Index = Index

Collections de collections

Mongo: ACID? ~Atomic (update)~, cohrent, isolation, durable

Data{ FirstName: "Jonathan", Address: "15 Wanamassa Point Road", Children: [ {Name: "Michael", Age: 10}, {Name: "Jennifer", Age: 8}, {Name: "Samantha", Age: 5}, {Name: "Elena", Age: 2} ]}BSON = Binary JSON

Lightweight, traversable and UTF-8Pas de schmaDonne htrognes (viter M coll)

Atomicit par document

Terminologie :Jointure = Donnes embarques

Key_id: ObjectId

12 bits:- 4 bits Timestamp (Unix)- 3 bits ID machine- 2 bits ID process- 3 bits Count

Example: 52af1a617e0b18d9448b4567 (hexa)

DBRefs- collection- _id- db (optional)

}

Similar UUID

Obligatoire

Cl 12 bits4 timestamp3 id machine2 id process3 compteur

Non brut visible en hexa 24 caractres

Map reduceMap: select process per documentReduce: combining data

function mapFunction() { emit(this.user_id, this.price);}

function reduceFunction(keyUserId, valuePrice) { return Array.sum(valuePrice);}

db.runCommand({ mapReduce: 'my_collection', map: mapFunction, Reduce: reduceFunction, out: 'map_reduce_results_collection', query: { old_date: { $gt: new Date('17/08/2005') } }})

V8 JavaScript engineV8 JavaScript engine

ECMAscript

V8 JavaScript Engine

standardized JSON

strict mode

Installation (Debian) & shell

Installation

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10$ echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

$ sudo apt-get update$ sudo apt-get install mongodb-10gen

$ sudo /etc/init.d/mongodb {status|start|stop|restart|reload|force-reload}

Installation

$ mongoMongoDB shell version 2.4.9connection to: test> show databasesdefault 0.203125GBtest 0.203125GBlocal 0.078125GBreseau 0.203125GB> use reseauswitched to db reseau> show collectionsnetworksystem.indexestraffic> db.traffic.count()8

MongoDB DriversClient libraries

C

C++

C#

Go

Erlang

Java

JavaScript

Node.js

Perl

PHP

Python

Ruby

Scala

http://docs.mongodb.org/ecosystem/drivers/

Community Supported Drivers

ActionScript3

ColdFusion

D

Dart

Delphi

Groovy

Lips

Lua

Objective C

Ocaml

Opa

PowerShell

R

Smalltalk

PHP - installation

$ sudo apt-get update$ sudo apt-get install php5-dev$ sudo pecl install mongo$ sudo php5enmod mongo

Client PHP

PHP classes & typesMongoClient

MongoDB

MongoCollection

MongoCursor

MongoId

MongoCode

MongoDate

MongoRegex

MongoBinData

MongoInt32

MongoInt64

MongoDBRef

MongoMinKey

MongoMaxKey

MongoTimestamp

MongoGridFS

MongoGridFSFile

MongoGridFSCursor

Donne une ide de l'implmentation de mongo dans PHP

PHP examples