SlideShare une entreprise Scribd logo
1  sur  58
Télécharger pour lire hors ligne
Getting started with
MongoDB and Scala



     Open Source Bridge
       June 27, 2012
        Sean Sullivan
Gilt Groupe
Gilt Portland
http://twitter.com/tinyrobots/status/217675630962163713
Jobs @ Gilt Portland

    • QA engineering
    • Backend engineering
    • Frontend engineering

#scala    #java   #ruby      #html5   #javascript
open source @ Gilt
• MongoDB
• Using Mongo and Scala together
• MongoDB at Gilt
“MongoDB is a document-oriented
database management system
designed for performance, horizontal
scalability, high availability, and
advanced queryability”


                     source: http://docs.mongodb.org/manual/about/
http://www.mongodb.org
https://github.com/mongodb/mongo
Licensing

Database: GNU AGPL v3.0

Drivers:      Apache License 2.0


     source: http://www.mongodb.org/display/DOCS/Licensing
Getting started
http://www.mongodb.org/downloads
http://www.mongodb.org/downloads
MongoDB concepts
MySQL            MongoDB
 database           database
    table          collection
   index             index
    row         BSON document
  column          BSON field
     join     embedding and linking
primary key         _id field
 group by         aggregation

                       source: mongodb.org
http://www.mongodb.org/display/DOCS/BSON
Embedding vs Linking

“Embedding is the nesting of objects and arrays inside a
BSON document”


“Links are references between documents”



                        source: http://www.mongodb.org/display/DOCS/Schema+Design
MongoDB on MacOS X

$ wget http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.0.6.tgz
$ tar -zxvf mongodb-osx-x86_64-2.0.6.tgz
$ sudo mkdir -p /data/db
$ sudo chown `id -u` /data/db
Starting MongoDB


$ mongod
Mongo shell


$ mongo
Mongo shell demo
Mongo shell
> use mydb
> obama = { name: “Obama” };
> db.presidents.save(obama);
> db.presidents.ensureIndex({ name: 1 });
> db.presidents.find({name: “Obama”});
> exit
Client libraries for the JVM
• mongo-java-driver   • Casbah
• Morphia             • Hammersmith
                      • Rogue
MongoDB Java driver
https://github.com/mongodb/mongo-java-driver/
mongo-java-driver
        and Maven

<dependency>
   <groupId>org.mongodb<groupId>
   <artifactId>mongo-java-driver<artifactId>
   <version>2.8.0<version>
<dependency>
mongo-java-driver
 example code
Morphia
http://code.google.com/p/morphia/
Morphia example code
Casbah
https://github.com/mongodb/casbah/
Casbah


• Scala toolkit for MongoDB
• built on top of the mongo-java-driver
Casbah

• Scala idioms
• Scala collections
• fluid query syntax
https://twitter.com/mongodb/status/217291079920254976
Casbah and Maven

<dependency>
   <groupId>org.mongodb<groupId>
   <artifactId>casbah_2.9.2<artifactId>
   <version>2.3.0<version>
<dependency>
Casbah and SBT


"org.mongodb" %% "casbah" % "2.3.0"
Casbah DBObject
import org.mongodb.casbah.Imports._

val mongoConn = MongoConnection(hostname, port)
val mongoDB = mongoConn(“test_db”)
val collection = mongoDB(“test_data”)

val newObj = MongoDBObject(“a” -> “apple”, “b” -> “banana”)
newObj += “c” -> “chocolate”

val a = newObject.getAs[String](“a”)
// a is an Option[String]




                                      http://api.mongodb.org/scala/casbah/current/tutorial.html
Casbah MongoDBList
// MongoDBList is a Mongo-friendly Scala List

import org.mongodb.casbah.Imports._

 val builder = MongoDBList.newBuilder
 builder += "foo"
 builder += "bar"
 builder += "x"
 builder += "y"
 val newLst = builder.result
 /* newLst: com.mongodb.BasicDBList = [ "foo" ,
"bar" , "x" , "y"] */


                             http://api.mongodb.org/scala/casbah/current/tutorial.html
Querying with Casbah
val mongoColl = MongoConnection()("test_db")("users")
val user1 = MongoDBObject("user" -> "barack",
                          "email" -> "barack@whitehouse.gov")
val user2 = MongoDBObject("user" -> "someOtherUser")
mongoColl += user1
mongoColl += user2
mongoColl.find()
// com.mongodb.casbah.MongoCursor =
// MongoCursor{Iterator[DBObject] with 2 objects.}

for { x <- mongoColl} yield x
/* Iterable[com.mongodb.DBObject] = List(
    { "_id" : { "$oid" : "4c3e2bec521142c87cc10faa"} ,
       "user" : "obama" ,
       "email" : "barack@whitehouse.gov"},
      { "_id" : { "$oid" : "4c3e2bec521142c87dc10fbb"} ,
       "user" : "someOtherUser"}
 ) */



                                             http://api.mongodb.org/scala/casbah/current/tutorial.html
Fluid querying with Casbah DSL

val q = "email" $exists true
// q: (String, com.mongodb.DBObject) =
// (email,{ "$exists" : true})
val users = for (x <- mongoColl.find(q))
yield x
assert(users.size == 1)




                        http://api.mongodb.org/scala/casbah/current/tutorial.html
Hammersmith
https://github.com/bwmcadams/hammersmith
Hammersmith

• new MongoDB driver for Scala
• pure Scala
• Asynchronous
• Not production ready at this time
MongoDB at Gilt
• feature configuration service
• global navigation service
• user service
Foursquare’s Fongo project
“Fongo is an in-memory java implementation of mongo.”

“[...] primary use is for lightweight unit testing where you
don't want to spin up a mongo process”
https://github.com/foursquare/fongo
Additional resources

• http://www.10gen.com/presentations
• http://www.mongodb.org
• http://www.slideshare.net/sullis
Questions?
THE END

Contenu connexe

Tendances

Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
MongoDB
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
titanlambda
 

Tendances (20)

Webinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsWebinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to Basics
 
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkConceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation Framework
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
 
Scalable XQuery Processing with Zorba on top of MongoDB
Scalable XQuery Processing with Zorba on top of MongoDBScalable XQuery Processing with Zorba on top of MongoDB
Scalable XQuery Processing with Zorba on top of MongoDB
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
Learn Ajax here
Learn Ajax hereLearn Ajax here
Learn Ajax here
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
 
Simple search with elastic search
Simple search with elastic searchSimple search with elastic search
Simple search with elastic search
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)
 
Polyglot Persistence
Polyglot PersistencePolyglot Persistence
Polyglot Persistence
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
 
Ajax
AjaxAjax
Ajax
 

Similaire à Getting started with MongoDB and Scala - Open Source Bridge 2012

MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
rfischer20
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
Tobias Trelle
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-final
MongoDB
 

Similaire à Getting started with MongoDB and Scala - Open Source Bridge 2012 (20)

Back to Basics Webinar 2 - Your First MongoDB Application
Back to  Basics Webinar 2 - Your First MongoDB ApplicationBack to  Basics Webinar 2 - Your First MongoDB Application
Back to Basics Webinar 2 - Your First MongoDB Application
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
 
Rails with mongodb
Rails with mongodbRails with mongodb
Rails with mongodb
 
Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Spring Data MongoDB 介紹
Spring Data MongoDB 介紹
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Morphia, Spring Data & Co.
Morphia, Spring Data & Co.Morphia, Spring Data & Co.
Morphia, Spring Data & Co.
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
 
From Zero to Mongo, Art.sy Experience w/ MongoDB
From Zero to Mongo, Art.sy Experience w/ MongoDBFrom Zero to Mongo, Art.sy Experience w/ MongoDB
From Zero to Mongo, Art.sy Experience w/ MongoDB
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP format
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-final
 

Plus de sullis

Incremental deployment of new features
Incremental deployment of new featuresIncremental deployment of new features
Incremental deployment of new features
sullis
 
Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010
sullis
 
Programming WebSockets - April 20 2010
Programming WebSockets - April 20 2010Programming WebSockets - April 20 2010
Programming WebSockets - April 20 2010
sullis
 

Plus de sullis (20)

Production Ready Web Services with Dropwizard
Production Ready Web Services with DropwizardProduction Ready Web Services with Dropwizard
Production Ready Web Services with Dropwizard
 
Incremental deployment of new features
Incremental deployment of new featuresIncremental deployment of new features
Incremental deployment of new features
 
Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011
 
Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011
 
Android 3.1 - Portland Code Camp 2011
Android 3.1 - Portland Code Camp 2011Android 3.1 - Portland Code Camp 2011
Android 3.1 - Portland Code Camp 2011
 
Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15
 
GWT 2.0 - OSCON 2010
GWT 2.0 - OSCON 2010GWT 2.0 - OSCON 2010
GWT 2.0 - OSCON 2010
 
Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010
 
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010
 
Programming WebSockets - April 20 2010
Programming WebSockets - April 20 2010Programming WebSockets - April 20 2010
Programming WebSockets - April 20 2010
 
WebDAV - April 15 2008
WebDAV - April 15 2008WebDAV - April 15 2008
WebDAV - April 15 2008
 
GWT 2.0 - December 15 2009
GWT 2.0 - December 15 2009GWT 2.0 - December 15 2009
GWT 2.0 - December 15 2009
 
Google App Engine - September 17 2009
Google App Engine - September 17 2009Google App Engine - September 17 2009
Google App Engine - September 17 2009
 
Google App Engine - Portland Java User Group - August 18 2009
Google App Engine - Portland Java User Group - August 18 2009Google App Engine - Portland Java User Group - August 18 2009
Google App Engine - Portland Java User Group - August 18 2009
 
Domo Arigato Mr. Roboto - Open Source Bridge 2009
Domo Arigato Mr. Roboto - Open Source Bridge 2009Domo Arigato Mr. Roboto - Open Source Bridge 2009
Domo Arigato Mr. Roboto - Open Source Bridge 2009
 
Java and JSON - UJUG - March 19 2009
Java and JSON - UJUG - March 19 2009Java and JSON - UJUG - March 19 2009
Java and JSON - UJUG - March 19 2009
 
OAuth and REST web services
OAuth and REST web servicesOAuth and REST web services
OAuth and REST web services
 
Introduction to Android - Mobile Fest Singapore 2009
Introduction to Android - Mobile Fest Singapore 2009Introduction to Android - Mobile Fest Singapore 2009
Introduction to Android - Mobile Fest Singapore 2009
 
Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009
 
Getting Started with Android - OSSPAC 2009
Getting Started with Android - OSSPAC 2009Getting Started with Android - OSSPAC 2009
Getting Started with Android - OSSPAC 2009
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Getting started with MongoDB and Scala - Open Source Bridge 2012