Community contributed extensions

The main concepts

PlayMorphia plugin is a Object-MongoDB mapping tool integrated with Play!Framework.

System architecture

Build on top of Play!framework plugin infrastructure and Morphia library, PlayMorphia hides complexity and provides an easy-to-user interface to application developers for MongoDB access.

Understand MongoDB

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

Unlike traditional SQL databases, MongoDB’s document oriented storage persist data in JSON-style documents with dynamic schemas.


Connection is a concept used in classic client-server system. In our context, MongoDB provides server process; your application takes the client role. In order to access server(MongoDB) resources, your application needs to connect to server.

In PlayMorphia, you configure the connection to MongoDB server with the morphia.db.seeds configuration. See here


MongoDB use databases to group a set of collections of data. A MongoDB server supports multiple databases. Each one of them are separate from each other, for security and ease of management.

At the moment PlayMorphia supports mapping data model to only one database though you are free to configure multiple databases. To configure the database used in your application, you use configuration. See here


A collection is roughly a table in traditional SQL database products. It groups a set of document(data) and (though not accurately) corresponds to a Morphia Model class in your application.

By default PlayMorphia map your model class to the collection with the same name of the model class. E.g. suppose you have the following model class:

@Entity public class User extends Model {...}

A collection named "User" will be created in your MongoDB database to store all the user document. However it is possible to specify a collection with different name. Let’s say if I want the User class be mapped to a collection name "profile", I could do it in this way:

@Entity("profile") public class User extends Model {...}

Click here for more information about the @Entity annotation.


Document is the way MongoDB call the record. The relationship between document and collection is just like that between row and table.

In PlayMorphia, one document corresponds to an instance of your Model class. You can easily create, read, update and delete a document by invoking corresponding method built into your Model class.

Understand Morphia

Created by Mr. Scott Hernandez, “Morphia is a type-safe library for mapping Java objects to/from MongoDB”.

The Morphia library is the cornerstone of PlayMorphia module, and it’s also how this module is named. Morphia library provides the following functions in this module:

  1. Mapping between Java Object and MongoDB document
  2. Query interface

Most interfaces/tools provided with Morphia have been carefully encapsulated or exposed in PlayMorphia in a way that make the programmer feel easy and comfortable. Actually it’s hard for you to aware that you are using Morphia or any other tools. Like other stuff in Play, things just happen naturally.

An interesting question is “Can I use Morphia directly in my Play application?”. Yes you can. But before you go ahead with that way, make sure you have read Why PlayMorphia.

PlayMorphia, seamless integration of MongoDB access into Play!Framework

MongoDB is wonderful, Morphia is nice, Play is amazing. PlayMorphia bring you a way to integrate these cool stuff together. With PlayMorphia module, writing code with MongoDB as backend in Play is not only easy but also fun!

  1. Simple configuration
  2. Automatically mapping model classes
  3. DB access methods built into your model class
  4. Transparent GridFS support
  5. Clear entity lifecycle event handling
  6. Powerful statistics in simple interface