Using MongoDB With Groovy

  • 7,652 views
Uploaded on

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

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • 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
No Downloads

Views

Total Views
7,652
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
62
Comments
1
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Using MongoDB with Groovy James Williams (@ecspike) BT/Ribbit
  • 2. Just as NoSQL is...
      • post - relational
      • schemaless
      • flexible
  • 3. Groovy is ...
      • a superset of Java
      • open to metaprogramming
      • a more concise way to write code
  • 4. 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]])
  • 5. 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(...)
  • 6. 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.
  • 7. Groovy + Mongo in the wild
  • 8. 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