Slide 1

Slide 1 text

How different are MongoDB Drivers? SA, MongoDB Norberto Leite #mongobe

Slide 2

Slide 2 text

{ "name": "Norberto Leite", "role": "Solutions Architect", "company": "MongoDB", "address": ["Barcelona, Spain”, ”Brussels, Belgium”] "contact": "[email protected]", "likes": { "beer": "Superbock", "software": ["Development", "python", "go", "databases"], "football": "FC Porto" } } Hi There!

Slide 3

Slide 3 text

Agenda •  MongoDB Drivers •  Community vs Official Supported •  General Considerations •  Examples •  Meta Driver Project

Slide 4

Slide 4 text

MongoDB Drivers

Slide 5

Slide 5 text

What’s a Driver? •  Native Language Library •  API that exposes methods to operate w/ MongoDB •  Serialization and Deserialization of native objects/ structures into BSON format –  http://bsonspec.org •  Handles the communication and pooling with server

Slide 6

Slide 6 text

struct MsgHeader { int32 messageLength; // total message size, including this int32 requestID; // identifier for this message int32 responseTo; // requestID from the original request // (used in reponses from db) int32 opCode; // request type - see table below } Driver Messages

Slide 7

Slide 7 text

struct OP_INSERT { MsgHeader header; // standard message header int32 flags; // bit vector - see below cstring fullCollectionName; // "dbname.collectionname" document* documents; // one or more documents to insert into the collection } Insert Message

Slide 8

Slide 8 text

struct OP_QUERY { MsgHeader header; // standard message header int32 flags; // bit vector of query options. See below for det cstring fullCollectionName ; // "dbname.collectionname" int32 numberToSkip; // number of documents to skip int32 numberToReturn; // number of documents to return // in the first OP_REPLY batch document query; // query object. See below for details. [ document returnFieldsSelector; ] // Optional. Selector indicating the fiel // to return. See below for details. } Query Message

Slide 9

Slide 9 text

How many drivers ? •  A few

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

How many drivers? •  13 officially supported drivers –  Python –  Java –  C / C++ / C# –  PHP –  Node.js –  Perl –  Ruby –  Scala –  … http://docs.mongodb.org/ecosystem/drivers/

Slide 12

Slide 12 text

How many drivers? •  Community Supported –  Matlab –  R –  Go –  Clojure –  Dart –  Erlang –  Prolog –  … http://docs.mongodb.org/ecosystem/drivers/community-supported-drivers/

Slide 13

Slide 13 text

Community vs Official Supported

Slide 14

Slide 14 text

Don’t take the RED PILL!

Slide 15

Slide 15 text

Things to consider •  Official driver means: –  We have dedicated resources to work on the driver –  Constant delivery and updated with server version –  Support includes fixes for drivers •  Some community drivers are also maintained by MongoDB engineers –  mongoengine –  motor –  …

Slide 16

Slide 16 text

But most important Use the best tool for the problem!

Slide 17

Slide 17 text

Language Ecosystem

Slide 18

Slide 18 text

Python •  Official Driver –  pymongo •  Frameworks | ODMs –  mongoengine –  minimongo –  Manga •  Alternative Drivers –  Asynchronous •  Motor •  TxMongo

Slide 19

Slide 19 text

> pip install pymongo //or > easy_install pymongo //using ipython > ipython >> from pymongo import MongoClient >> mc = MongoClient() Python

Slide 20

Slide 20 text

Node.js •  Official Driver –  http://mongodb.github.io/node-mongodb-native/ •  ODM –  Mongose •  http://mongoosejs.com/ •  Others –  Mongoskin –  Mongolia http://docs.mongodb.org/ecosystem/drivers/node-js/

Slide 21

Slide 21 text

> node >> var MongoClient = require("mongodb").MongoClient >> MongoClient.connect( "mongodb://nair.local:27017", function(err, db){ if(!err) {console.log("we are connected");} }); >> var col = db.collection("sample"); Node.js

Slide 22

Slide 22 text

Java •  Official Driver –  http://api.mongodb.org/java/current/index.html •  Multiple Frameworks –  Morphya –  DataNucleus JPA/JDO –  Jongo •  JVM Languages –  Scala –  Clojure –  Groovy

Slide 23

Slide 23 text

Clojure

Slide 24

Slide 24 text

(ns my.service.server (:require [monger.core :as mg]) (:import [com.mongodb MongoOptions ServerAddress])) ;; localhost, default port (mg/connect!) ;; set default database using set-db (mg/set-db! (mg/get-db "monger-test")) Clojure

Slide 25

Slide 25 text

Go •  Not officially supported driver! •  mgo Library –  http://labix.org/mgo –  Really cool! –  We use it internally for some projects •  Others –  gomongo –  go-mongo

Slide 26

Slide 26 text

Let’s get some code Running!

Slide 27

Slide 27 text

MongoDB Meta Driver Project

Slide 28

Slide 28 text

Meta Driver •  http://docs.mongodb.org/meta-driver/latest/ •  Help new drivers to be built by the community •  Basic structure and conventions documentation •  Beta Project – Under Development

Slide 29

Slide 29 text

Obrigado! [email protected] Norberto Leite @nleite