Yet Another Flavour of GORM: MongoDB

Engineering | Graeme Rocher | November 15, 2010 | ...

Our crusade to make GORM ubiquitous across NoSQL stores hit another milestones today as we are pleased to announce GORM for MongoDB.

MongoDB is a document database that bridges the gap between key-value stores (which are fast and highly scalable) and traditional RDBMS systems (which provide rich queries and deep functionality).

Like the Redis and Gemfire plugins, GORM for MongoDB has full support for CRUD operations:

def person = new Person(name:"Fred", age: 45)
person.save()

person = Person.get(person.id)
assert person != null

person.delete()

assert Person.get(person.id) == null

Rich querying with dynamic finders:

def fred = Person.findByName("Fred")
def adults = Person.findAllByAgeGreaterThan(18)
def teenagers = Person.findAllByAgeBetween(13, 18)
def children = Person.findAllByAgeLessThan(13)

Complex query handling with criteria queries:

def results = Person.withCriteria {
    like('name', 'F%')
    gt('age', 18)
}

And reusable query support with named queries:

class Person {
   String name
   int age

   static namedQueries = {
         adults { gt 'age', 18 }
         childrenStartingWithF {
              lt 'age', 18
              like 'name', 'F%'
         }
   }
}

Person.adults.list()
Person.adults.findByName("Fred")
Person.childrenStartingWithF.count()

All this whilst still allowing access to the lower-level Mongo driver:

def fred = Person.collection.findOne(name:"Fred")

We have prepared a short screencast demonstrating GORM for MongoDB in action:

GORM for MongoDB Screencast

You can checkout the full documentation on the GORM for MongoDB plugin for more information on installation, configuration and working with the APIs.

GORM for MongoDB is built on the same codebase as the Redis and Gemfire support, speaking of which we are extremely excited with upcoming community contributions to the code, including support for Java Content Repository (JCR) and Riak (a scalable key/value datastore with a nice REST API).

We continue to be keen to work with the community on building out support for GORM implementations on top of other datastores, if you're interested in helping out give us a shout on the Grails mailing list.

Enjoy!

Get the Spring newsletter

Thank you for your interest. Someone will get back to you shortly.

Get ahead

VMware offers training and certification to turbo-charge your progress.

Learn more

Get support

Tanzu Spring Runtime offers support and binaries for OpenJDK™, Spring, and Apache Tomcat® in one simple subscription.

Learn more

Upcoming events

Check out all the upcoming events in the Spring community.

View all