Download - How Different are MongoDB Drivers

Transcript
Page 1: How Different are MongoDB Drivers

How different are MongoDB Drivers?

SA, MongoDB

Norberto Leite

#mongobe

Page 2: How Different are MongoDB Drivers

{ "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!

Page 3: How Different are MongoDB Drivers

Agenda

•  MongoDB Drivers

•  Community vs Official Supported

•  General Considerations

•  Examples

•  Meta Driver Project

Page 4: How Different are MongoDB Drivers

MongoDB Drivers

Page 5: How Different are MongoDB Drivers

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

Page 6: How Different are MongoDB Drivers

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

Page 7: How Different are MongoDB Drivers

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

Page 8: How Different are MongoDB Drivers

struct OP_QUERY {

MsgHeader header; // standard message header

int32 flags; // bit vector of query options. See below for details.

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 fields

// to return. See below for details.

}

Query Message

Page 9: How Different are MongoDB Drivers

How many drivers ?

•  A few

Page 10: How Different are MongoDB Drivers
Page 11: How Different are MongoDB Drivers

How many drivers?

•  13 officially supported drivers –  Python –  Java –  C / C++ / C# –  PHP –  Node.js –  Perl –  Ruby –  Scala –  …

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

Page 12: How Different are MongoDB Drivers

How many drivers?

•  Community Supported –  Matlab –  R –  Go –  Clojure –  Dart –  Erlang –  Prolog –  …

http://docs.mongodb.org/ecosystem/drivers/community-supported-drivers/

Page 13: How Different are MongoDB Drivers

Community vs Official Supported

Page 14: How Different are MongoDB Drivers

Don’t take the RED PILL!

Page 15: How Different are MongoDB Drivers

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 –  …

Page 16: How Different are MongoDB Drivers

But most important Use the best tool for the problem!

Page 17: How Different are MongoDB Drivers

Language Ecosystem

Page 18: How Different are MongoDB Drivers

Python

•  Official Driver –  pymongo

•  Frameworks | ODMs –  mongoengine –  minimongo –  Manga

•  Alternative Drivers –  Asynchronous •  Motor •  TxMongo

Page 19: How Different are MongoDB Drivers

> pip install pymongo

//or

> easy_install pymongo

//using ipython

> ipython

>> from pymongo import MongoClient

>> mc = MongoClient()

Python

Page 20: How Different are MongoDB Drivers

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/

Page 21: How Different are MongoDB Drivers

> 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

Page 22: How Different are MongoDB Drivers

Java

•  Official Driver –  http://api.mongodb.org/java/current/index.html

•  Multiple Frameworks –  Morphya –  DataNucleus JPA/JDO –  Jongo

•  JVM Languages –  Scala –  Clojure –  Groovy

Page 23: How Different are MongoDB Drivers

Clojure

Page 24: How Different are MongoDB Drivers

(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

Page 25: How Different are MongoDB Drivers

Go

•  Not officially supported driver!

•  mgo Library –  http://labix.org/mgo –  Really cool! –  We use it internally for some projects

•  Others –  gomongo –  go-mongo

Page 26: How Different are MongoDB Drivers

Let’s get some code Running!

Page 27: How Different are MongoDB Drivers

MongoDB Meta Driver Project

Page 28: How Different are MongoDB Drivers

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

Page 29: How Different are MongoDB Drivers

Obrigado!

[email protected]

Norberto Leite

@nleite