Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
executable file 103 lines (71 sloc) 3.36 KB

MongoDB Salat plugin for Play Framework 2 (Scala only)

Salat is a ORM for MongoDBs scala driver called Casbah.

Build Status


Use g8 to start a new salat enabled play project

Install g8 on OSX using homebrew

brew update && brew install giter8

Or read about the other ways to install giter8 here

Then run

g8 leon/play-salat.g8

It will ask you a couple of questions, and your ready to rock 'n roll.

Manual installation

Start by adding the plugin, in your project/Build.scala

val appDependencies = Seq(
  "se.radley" %% "play-plugins-salat" % "1.0.4"

Then we can add the implicit converstions to and from ObjectId by adding to the routesImport and add ObjectId to all the templates

val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
  routesImport += "se.radley.plugin.salat.Binders._",
  templatesImport += "org.bson.types.ObjectId"

We now need to register the plugin, this is done by creating(or appending) to the conf/play.plugins file


We continue to edit the conf/application.conf file. We need to disable some plugins that we don't need. Add these lines:

dbplugin = disabled
evolutionplugin = disabled
ehcacheplugin = disabled


now we need to setup our connections. The plugin is modeled after how plays DB plugin is built.

mongodb.default.db = "mydb"
# Optional values = ""
#mongodb.default.port = 27017
#mongodb.default.user = "leon"
#mongodb.default.password = "123456"

# MongoURI
# ~~~~~
# a MongoURI can also be used
# mongodb.default.uri = "mongodb://,"

# WriteConcern
# ~~~~~
# Can be any of the following
# fsyncsafe - Exceptions are raised for network issues and server errors; Write operations wait for the server to flush data to disk.
# replicassafe - Exceptions are raised for network issues and server errors; waits for at least 2 servers for the write operation.
# safe - Exceptions are raised for network issues and server errors; waits on a server for the write operation.
# normal - Exceptions are raised for network issues but not server errors.

#mongodb.default.writeconcern = "safe"

# Replica sets
# ~~~~~
# To user a replicaset instead of a single host, omit optional values and use the configuration below instead.
# Since replica sets use public key authentication, user and password won't work together with the replicaset option.

#mongodb.default.replicaset {
# = ""
# = ""
#    host2.port = 27018

More that one DB?

If you would like to connect to two databases you need to create two source names

mongodb.myotherdb.db = "otherdb"

Then you can call mongoCollection("collectionname", "myotherdb")


If your using Scala Enumerations have a look at my play-enumeration project.

Jump to Line
Something went wrong with that request. Please try again.