(Quick Reference)

1 Introduction - Reference Documentation

Authors: Graeme Rocher, Burt Beckwith

Version: 5.0.8.RELEASE

1 Introduction

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

MongoDB (from "humongous") is a scalable, high-performance, open source, document-oriented database.

This project aims to provide an object-mapping layer on top of Mongo to ease common activities such as:

  • Marshalling from Mongo to Groovy/Java types and back again
  • Support for GORM dynamic finders, criteria and named queries
  • Session-managed transactions
  • Validating domain instances backed by the Mongo datastore

1.1 Compatibility with GORM for Hibernate

This implementation tries to be as compatible as possible with GORM for Hibernate. In general you can refer to the GORM documentation and the "Domain Classes" section of the reference guide (see the right nav) for usage information.

The following key features are supported by GORM for Mongo:

  • Simple persistence methods
  • Dynamic finders
  • Criteria queries
  • Named queries
  • Inheritance
  • Embedded types
  • Query by example

However, some features are not supported:

  • HQL queries
  • Composite primary keys
  • Many-to-many associations (these can be modelled with a mapping class)
  • Any direct interaction with the Hibernate API
  • Custom Hibernate user types (custom types are allowed with a different API)

There may be other limitations not mentioned here so in general it shouldn't be expected that an application based on GORM for Hibernate will "just work" without some tweaking involved. Having said that, the large majority of common GORM functionality is supported.

1.2 Release Notes

Below are the details of the changes across releases:

5.0

  • MongoDB 3.x driver support
  • New Codec Persistence Engine
  • Removal of GMongo
  • Trait based

4.0

  • Grails 3 compatibility

3.0

  • Support for MongoDB 2.6
  • MongoDB 2.6 GeoJSON type support (MultiPoint, MultiLineString, MultiPolygon and GeometryCollection)
  • Support for Maps of embedded entities
  • Flexible index definition
  • Full text search support
  • Support for projections using MongoDB aggregation
  • Size related criteria implemented (sizeEq, sizeLt etc.) on collections

2.0

  • GeoJSON shape support
  • Support for SSL connections
  • Support for MongoDB connection strings

1.3

  • Support for stateless mode to improve read performance
  • Support for dynamically switching which database or collection to persist to at runtime

1.2

MongoDB plugin 1.2 and above requires Grails 2.1.5 or 2.2.1 as a minimum Grails version, if you are using older versions of Grails you will need to stay with 1.1

1.1 GA

  • DBRefs no longer used by default for associations
  • Upgrade to GMongo 1.0 and Spring Data MongoDB 1.1
  • Support for global mapping configuration

1.0 GA

  • Initial feature complete 1.0 release

1.3 Upgrade Notes

Configuration Properties

In previous versions of the plugin configuration was specified using the `grails.mongo` prefix. This is now `grails.mongodb` instead. For example, the following configuration in application.groovy or Config.groovy:

grails {
    mongo {
        databaseName = 'foo'
    }
}

Should now be expressed as:

grails {
    mongodb {
        databaseName = 'foo'
    }
}

Persistence Engine

Since GORM for MongoDB 5.0 there is now a choice of persistence engine. The original GORM for MongoDB converted MongoDB documents to and from Groovy objects. This engine is still present and can be activated with the following configuration in grails-app/conf/application.yml:

grails:
    mongodb:
        engine: mapping

However, 5.0 and above uses a new engine based on MongoDB 3.x driver codecs which means objects are no longer converted first to MongoDB Document objects and then to Groovy objects, instead the driver reads Groovy objects directly from the JSON stream at the driver level, which is far more efficient, however may not exhibit exactly the same behaviour as the previous version. To active this new engine use the following codec (or leave it blank as the codec engine is now the default):

grails:
    mongodb:
        engine: codec