Your SlideShare is downloading. ×
Using MongoDB With Groovy
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Using MongoDB With Groovy

7,760
views

Published 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

Published in: Technology

1 Comment
1 Like
Statistics
Notes
  • 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
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
7,760
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
63
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