Using MongoDB With Groovy
Upcoming SlideShare
Loading in...5
×
 

Using MongoDB With Groovy

on

  • 10,031 views

Lightning talk showing how to make MongoDB more Groovy

Lightning talk showing how to make MongoDB more Groovy

Given at NoSQL Live Boston
March 11,2010

Statistics

Views

Total Views
10,031
Views on SlideShare
9,164
Embed Views
867

Actions

Likes
1
Downloads
61
Comments
1

8 Embeds 867

http://nosql.pl 754
http://nosql.mypopescu.com 50
http://www.slideshare.net 27
http://localhost 21
http://nosqlpl.tumblr.com 10
http://bender 3
http://webcache.googleusercontent.com 1
http://web.archive.org 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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…
  • For more info on Groovy metaprogramming, check out: http://www.slideshare.net/fuglylogic/mopping-up-with-groovy-presentation [PDF] http://www.grails-exchange.com/files/GraemeRocher%20-%20Keynote-DynamicGroovyMetaMagic.pdf
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Using MongoDB With Groovy Using MongoDB With Groovy Presentation Transcript

  • Using MongoDB with Groovy James Williams (@ecspike) BT/Ribbit
  • Just as NoSQL is...
      • post - relational
      • schemaless
      • flexible
  • Groovy is ...
      • a superset of Java
      • open to metaprogramming
      • a more concise way to write code
  • Groovy + Mongo
      • Java
    • BasicDBObject doc = new BasicDBObject();
    • doc.put("name", "MongoDB");
    • doc.put("type", "database");
    • doc.put("count", 1);
    • coll.insert(doc);
      • Groovier
    • def doc = [name:"MongoDB", count:1,type:"database", info: [x:203, y:102]
    •            ] as BasicDBObject
    • coll.insert(doc)
      • Grooviest (using groovy-mongo)
    • coll.insert([name:"MongoDB", type:"database", info: [x:203, y:102]])
  • Dynamic Finders
      • let you query the database as if there was a schema
      • build complex query functions at runtime
    •          Ex. collection.findByAuthorAndPostCreatedGreaterThan(...)
    •           collection.findByComments_CreatedOn(...)
  • How dynamic finders work
      • Groovy tries to execute the function but can't find it
      • It invokes methodMissing instead
      • The body of methodMissing takes the attempted method name and parses it
      • It uses the names and the modifiers (>, <, etc) with BasicDBObjectBuilder to create a prototype
      • It caches the created function under that name and runs it. 
      • Further invocations don't incur the performance hit.
  • Groovy + Mongo in the wild
  • Links
      • Andrill: http://andrill.org
      • CoreRef: http://coreref.org
      • groovy-mongo: http://github.com/jwill/groovy-mongo
      • Personal Blog: http://jameswilliams.be/blog
      • Twitter: @ecspike