(Quick Reference)

5 Low Level Access - Reference Documentation

Authors: Juri Kuehn

Version: 0.8.0

5 Low Level Access

If you want to, you can also access Morphia's Datastore or the underlying MongoDB Java Driver directly. Morphia is used to transform between MongoDB DBObjects and annotated POJOs. The Java Driver can be used for slick low level access to MongoDB.

Access using the mongo bean

The bean mongo provides access to the configured java driver and morphia instance (since 0.1.2):

usage:

class MongoController {
    def mongo

def lowlevel = { mongo.mongo // com.mongodb.Mongo - already connected mongo.db // com.mongodb.DB - configured db mongo.morphia // com.google.code.morphia.Morphia - used for mapping mongo.datastore // com.google.code.morphia.Datastore - ORM layer

// com.mongodb.DBCollection that holds entities for given class mongo.getCollection(Person.class) } }

Access using the collection property

Every MongoDB domain has a collection property for convenient access to the drivers DBCollection instance:

usage example:

Project.collection.insert(new BasicDBObject('name', 'Project MongoDB'))