Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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      #h...
open source @ Gilt
• MongoDB• Using Mongo and Scala together• MongoDB at Gilt
“MongoDB is a document-orienteddatabase management systemdesigned for performance, horizontalscalability, high availabilit...
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        ...
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 do...
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...
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...
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>...
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<versi...
Casbah and SBT"org.mongodb" %% "casbah" % "2.3.0"
Casbah DBObjectimport org.mongodb.casbah.Imports._val mongoConn = MongoConnection(hostname, port)val mongoDB = mongoConn(“...
Casbah MongoDBList// MongoDBList is a Mongo-friendly Scala Listimport org.mongodb.casbah.Imports._ val builder = MongoDBLi...
Querying with Casbahval mongoColl = MongoConnection()("test_db")("users")val user1 = MongoDBObject("user" -> "barack",    ...
Fluid querying with Casbah DSLval q = "email" $exists true// q: (String, com.mongodb.DBObject) =// (email,{ "$exists" : tr...
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...
https://github.com/foursquare/fongo
Additional resources• http://www.10gen.com/presentations• http://www.mongodb.org• http://www.slideshare.net/sullis
Questions?
THE END
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
Upcoming SlideShare
Loading in …5
×

Getting started with MongoDB and Scala - Open Source Bridge 2012

9,329 views

Published on

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

Published in: Technology, Education
  • Be the first to comment

Getting started with MongoDB and Scala - Open Source Bridge 2012

  1. 1. Getting started withMongoDB and Scala Open Source Bridge June 27, 2012 Sean Sullivan
  2. 2. Gilt Groupe
  3. 3. Gilt Portland
  4. 4. http://twitter.com/tinyrobots/status/217675630962163713
  5. 5. Jobs @ Gilt Portland • QA engineering • Backend engineering • Frontend engineering#scala #java #ruby #html5 #javascript
  6. 6. open source @ Gilt
  7. 7. • MongoDB• Using Mongo and Scala together• MongoDB at Gilt
  8. 8. “MongoDB is a document-orienteddatabase management systemdesigned for performance, horizontalscalability, high availability, andadvanced queryability” source: http://docs.mongodb.org/manual/about/
  9. 9. http://www.mongodb.org
  10. 10. https://github.com/mongodb/mongo
  11. 11. LicensingDatabase: GNU AGPL v3.0Drivers: Apache License 2.0 source: http://www.mongodb.org/display/DOCS/Licensing
  12. 12. Getting started
  13. 13. http://www.mongodb.org/downloads
  14. 14. http://www.mongodb.org/downloads
  15. 15. MongoDB concepts
  16. 16. 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
  17. 17. http://www.mongodb.org/display/DOCS/BSON
  18. 18. 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
  19. 19. 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
  20. 20. Starting MongoDB$ mongod
  21. 21. Mongo shell$ mongo
  22. 22. Mongo shell demo
  23. 23. Mongo shell> use mydb> obama = { name: “Obama” };> db.presidents.save(obama);> db.presidents.ensureIndex({ name: 1 });> db.presidents.find({name: “Obama”});> exit
  24. 24. Client libraries for the JVM
  25. 25. • mongo-java-driver • Casbah• Morphia • Hammersmith • Rogue
  26. 26. MongoDB Java driver
  27. 27. https://github.com/mongodb/mongo-java-driver/
  28. 28. mongo-java-driver and Maven<dependency> <groupId>org.mongodb<groupId> <artifactId>mongo-java-driver<artifactId> <version>2.8.0<version><dependency>
  29. 29. mongo-java-driver example code
  30. 30. Morphia
  31. 31. http://code.google.com/p/morphia/
  32. 32. Morphia example code
  33. 33. Casbah
  34. 34. https://github.com/mongodb/casbah/
  35. 35. Casbah• Scala toolkit for MongoDB• built on top of the mongo-java-driver
  36. 36. Casbah• Scala idioms• Scala collections• fluid query syntax
  37. 37. https://twitter.com/mongodb/status/217291079920254976
  38. 38. Casbah and Maven<dependency> <groupId>org.mongodb<groupId> <artifactId>casbah_2.9.2<artifactId> <version>2.3.0<version><dependency>
  39. 39. Casbah and SBT"org.mongodb" %% "casbah" % "2.3.0"
  40. 40. 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
  41. 41. 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
  42. 42. 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
  43. 43. 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
  44. 44. Hammersmith
  45. 45. https://github.com/bwmcadams/hammersmith
  46. 46. Hammersmith• new MongoDB driver for Scala• pure Scala• Asynchronous• Not production ready at this time
  47. 47. MongoDB at Gilt
  48. 48. • feature configuration service• global navigation service• user service
  49. 49. Foursquare’s Fongo project
  50. 50. “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”
  51. 51. https://github.com/foursquare/fongo
  52. 52. Additional resources• http://www.10gen.com/presentations• http://www.mongodb.org• http://www.slideshare.net/sullis
  53. 53. Questions?
  54. 54. THE END

×