0
votes

I am new in play framework 2. I have play 2 with scala and MongoDb requirement. I searched lots on Play 2 and MongoDb connection, but didn't find any useful documentation.

There is lots of plugins available eg. Casbah, Reactive Mongo, Salat. So which is best for use, and which have better future?

If i want to implement my own connection to Mongo without using third party plugin, is it possible?

Please give examples and document on Play 2 and MongoDB connection.

2
I used play Scala and play MongoDB using Casbah and Salat from past one year, without any problem I handle mongo aggregation, mongo replication using Salat. My personal opinion is play Scala better integrated using Casbah and Salat - Yogesh
It depends on the requirement, if you have to upload a large size files( more than 100 mb), you could use reactivemongo, which has gridfs body parser for reactive uploading. - S.Karthik

2 Answers

1
votes

I suggest using ReactiveMongo as its non-blocking approach is similar to how Play itself works. The API works with scala Futures which is a a really nice fit with Play's Async actions. You can also use their macros to convert case classes straight to BSON sparing quite some boilerplate code.

0
votes

A lot of time has passed but I would like to share an update for those, who may search for Scala MongoDB client library for Play Framework.

Reactive Mongo is great but still lacks Play Framework 2.4 integration and MongoDB 3.0. We have waited for a long time thus wrote a library that wraps original MongodDB client in the Scala style way and is similar to Reactive Mongo in the api. Take a look at https://github.com/evojam/play-mongodb-driver. With the Play Framework module it's pretty straightforward to start, like few minutes to get working code.

This way MongoDB is nice and easy to use in Scala. We have provided a comparison of the sample query execution is in our blog post about the driver on site.