SlideShare a Scribd company logo
Getting started with
MongoDB and Scala



     Open Source Bridge
       June 27, 2012
        Sean Sullivan
Getting started with MongoDB and Scala - Open Source Bridge 2012
Gilt Groupe
Getting started with MongoDB and Scala - Open Source Bridge 2012
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
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
‱ 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 ïŹeld
     join     embedding and linking
primary key         _id ïŹeld
 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.ïŹnd({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
‱ ïŹ‚uid 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 conïŹguration 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

More Related Content

What's hot (20)

PPTX
Conceptos bĂĄsicos. Seminario web 5: IntroducciĂłn a Aggregation Framework
MongoDB
 
ODP
2011 Mongo FR - Indexing in MongoDB
antoinegirbal
 
PPTX
Back to Basics Webinar 5: Introduction to the Aggregation Framework
MongoDB
 
PDF
Java Persistence Frameworks for MongoDB
MongoDB
 
PDF
Benchx: An XQuery benchmarking web application
Andy Bunce
 
PPT
Advanced Json
guestfd7d7c
 
PDF
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
DataStax
 
PDF
Scalable XQuery Processing with Zorba on top of MongoDB
William Candillon
 
PDF
Building Apps with MongoDB
Nate Abele
 
PDF
Json tutorial, a beguiner guide
Rafael Montesinos Muñoz
 
PDF
Learn Ajax here
jarnail
 
PDF
Mongo Presentation by Metatagg Solutions
Metatagg Solutions
 
PDF
JSON Fuzzing: New approach to old problems
titanlambda
 
PDF
Simple search with elastic search
markstory
 
PPTX
JSON-(JavaScript Object Notation)
Skillwise Group
 
PDF
Polyglot Persistence
Scott Leberknight
 
PPTX
MongoDB + Java - Everything you need to know
Norberto Leite
 
PPTX
Webinaire 2 de la série « Retour aux fondamentaux » : Votre premiÚre applicat...
MongoDB
 
PPT
Ajax
Manav Prasad
 
PPTX
JSON
Yoga Raja
 
Conceptos bĂĄsicos. Seminario web 5: IntroducciĂłn a Aggregation Framework
MongoDB
 
2011 Mongo FR - Indexing in MongoDB
antoinegirbal
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
MongoDB
 
Java Persistence Frameworks for MongoDB
MongoDB
 
Benchx: An XQuery benchmarking web application
Andy Bunce
 
Advanced Json
guestfd7d7c
 
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
DataStax
 
Scalable XQuery Processing with Zorba on top of MongoDB
William Candillon
 
Building Apps with MongoDB
Nate Abele
 
Json tutorial, a beguiner guide
Rafael Montesinos Muñoz
 
Learn Ajax here
jarnail
 
Mongo Presentation by Metatagg Solutions
Metatagg Solutions
 
JSON Fuzzing: New approach to old problems
titanlambda
 
Simple search with elastic search
markstory
 
JSON-(JavaScript Object Notation)
Skillwise Group
 
Polyglot Persistence
Scott Leberknight
 
MongoDB + Java - Everything you need to know
Norberto Leite
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre premiÚre applicat...
MongoDB
 
Ajax
Manav Prasad
 
JSON
Yoga Raja
 

Similar to Getting started with MongoDB and Scala - Open Source Bridge 2012 (20)

PPT
Scala with MongoDB
Abdhesh Kumar
 
PDF
Scalany mongodb aug10
bwmcadams
 
PDF
Getting Started with MongoDB
Michael Redlich
 
PPT
Tech Gupshup Meetup On MongoDB - 24/06/2016
Mukesh Tilokani
 
PDF
Building Your First MongoDB Application
Tugdual Grall
 
PDF
MongoDB: a gentle, friendly overview
Antonio Pintus
 
PDF
Getting Started with MongoDB (TCF ITPC 2014)
Michael Redlich
 
PPTX
Mongodb Introduction
Nabeel Naqeebi
 
PDF
Embedding a language into string interpolator
Michael Limansky
 
PDF
3-Mongodb and Mapreduce Programming.pdf
MarianJRuben
 
PPTX
mongodb introduction11111111111111111111
VADAPALLYPRAVEENKUMA1
 
PDF
MongoDB
wiTTyMinds1
 
PDF
Mongony aug10
bwmcadams
 
PDF
Building your first app with MongoDB
Norberto Leite
 
PPTX
MongoDB using Grails plugin by puneet behl
TO THE NEW | Technology
 
PDF
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
PPTX
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
PPTX
Mondodb
Paulo Fagundes
 
PDF
Mongodb tutorial
Ashoka Vanjare
 
Scala with MongoDB
Abdhesh Kumar
 
Scalany mongodb aug10
bwmcadams
 
Getting Started with MongoDB
Michael Redlich
 
Tech Gupshup Meetup On MongoDB - 24/06/2016
Mukesh Tilokani
 
Building Your First MongoDB Application
Tugdual Grall
 
MongoDB: a gentle, friendly overview
Antonio Pintus
 
Getting Started with MongoDB (TCF ITPC 2014)
Michael Redlich
 
Mongodb Introduction
Nabeel Naqeebi
 
Embedding a language into string interpolator
Michael Limansky
 
3-Mongodb and Mapreduce Programming.pdf
MarianJRuben
 
mongodb introduction11111111111111111111
VADAPALLYPRAVEENKUMA1
 
MongoDB
wiTTyMinds1
 
Mongony aug10
bwmcadams
 
Building your first app with MongoDB
Norberto Leite
 
MongoDB using Grails plugin by puneet behl
TO THE NEW | Technology
 
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Mondodb
Paulo Fagundes
 
Mongodb tutorial
Ashoka Vanjare
 
Ad

More from sullis (20)

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

Recently uploaded (20)

PDF
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
Home Cleaning App Development Services.pdf
V3cube
 
PPTX
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
 
PDF
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
PPTX
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
NASA A Researcher’s Guide to International Space Station : Fundamental Physics
Dr. PANKAJ DHUSSA
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Home Cleaning App Development Services.pdf
V3cube
 
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
 
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
NASA A Researcher’s Guide to International Space Station : Fundamental Physics
Dr. PANKAJ DHUSSA
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Digital Circuits, important subject in CS
contactparinay1
 

Getting started with MongoDB and Scala - Open Source Bridge 2012