2012-06-22

Recently our group has been debating about switching to MongoDB. As a number of our analysis tools are written in Scala, naturally we'd like a Scala or Java ORM.

After some search, we've decided to explore Rogue, a type-safe DSL for querying MongoDB. Here's some motivation from the Foursquare engineers for developing Rogue, after using Lift for their ORM:

Essentially, we found the querying support a bit too expressive — you can pass in a query object that doesn’t represent a valid query, or query against fields that aren’t part of the record. And in addition it isn’t very type-safe. You can ask for, say, all Venue records where mayor = “Bob”, and it happily executes that query for you, returning nothing, never informing you that the mayor field is not a String but a Long representing the ID of the user. Well, we thought we could use the Scala type system to prevent this from ever happening, and that’s what we set out to do.

The idea of compile-time query sanity checks is pretty neat. Unfortunately Rogue documentation is fairly sparse, though people are quite helpful on the mailing list and there is some example code I've linked to below.

Links

Troubleshooting

Rogue's GitHub page recommends including the following in your build.sbt to use Rogue:

val rogue = "com.foursquare" %% "rogue" % "1.1.8" intransitive()
val liftMongoRecord = "net.liftweb" %% "lift-mongodb-record" % "2.4-M2"

However, lift-mongodb-record version 2.4-M2 could not be resolved for me using scala 2.9.1 and sbt 0.11.2. Using the "-M4" version enabled sbt to resolve it.

val liftMongoRecord = "net.liftweb" %% "lift-mongodb-record" % "2.4-M4"


blog comments powered by Disqus