• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Getting started with MongoDB and Scala - Open Source Bridge 2012
 

Getting started with MongoDB and Scala - Open Source Bridge 2012

on

  • 6,637 views

Getting started with MongoDB and Scala

Getting started with MongoDB and Scala
Open Source Bridge
June 27 2012
Portland Oregon

Statistics

Views

Total Views
6,637
Views on SlideShare
6,624
Embed Views
13

Actions

Likes
8
Downloads
108
Comments
0

4 Embeds 13

https://si0.twimg.com 5
http://www.twylah.com 4
https://twitter.com 3
http://us-w1.rockmelt.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Getting started with MongoDB and Scala - Open Source Bridge 2012 Getting started with MongoDB and Scala - Open Source Bridge 2012 Presentation Transcript

    • Getting started withMongoDB 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-orienteddatabase management systemdesigned for performance, horizontalscalability, high availability, andadvanced queryability” source: http://docs.mongodb.org/manual/about/
    • http://www.mongodb.org
    • https://github.com/mongodb/mongo
    • LicensingDatabase: GNU AGPL v3.0Drivers: 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 linkingprimary 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 aBSON 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 DBObjectimport 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 Listimport 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 Casbahval mongoColl = MongoConnection()("test_db")("users")val user1 = MongoDBObject("user" -> "barack", "email" -> "barack@whitehouse.gov")val user2 = MongoDBObject("user" -> "someOtherUser")mongoColl += user1mongoColl += user2mongoColl.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 DSLval q = "email" $exists true// q: (String, com.mongodb.DBObject) =// (email,{ "$exists" : true})val users = for (x <- mongoColl.find(q))yield xassert(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 youdont 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