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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Using MongoDB With Groovy

7,888

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,888
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

×