Play framework 2 scala with MongoDB - mongodb

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.

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.

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.

Related

Difference between ReactiveMongo , Mongo-Module and MongoHelper

Mongo with Play-Framework is new for me. I have Spring-Framework background, In which we create Controller, Business and DAO layer structure applications. Now, i want to taste the flavor of Play-Framework with ReactiveMongo. For create our sample Application, my first target is to follow Controller, Business and DAO layer structure. Play-Framework already provide the basic structure of application, which is really good. If we use Mongodb with Play-Framework, I found three types of MongoDB Drivers. These are as below:
Mongo Module (https://www.playframework.com/modules/mongo-1.1/home)
MongoHelper (https://gist.github.com/harmeetsingh0013/fdc9c20b056a62f303f5)
ReactiveMongo(http://reactivemongo.org/)
ReactiveMongo, which is really awesome for implementing non-blocking I/O. In reactive mongo there are some problem with sync the data from multiple queries. I have some queries for creating sample application as below:
My first target is to implement MVC using ReactiveMongo, which i think ReactiveMongo-Extension provide me Dao layer. But i still want to confirm, ReactiveMongo-Extension is a good approach ? or I need to go for MongoHelper? What is the benefit of Mongo-Module over reactive mongo?
For dependency Injection we need to go for Spring-Dependency Injection or Guice or other Scala Dependency Injection Framework ?
If i am go for ReactiveMongo, we need to go for JSONCollection because BSONCollection is MongoDB Dependency. What is the support for JSONCollection available?
Current modules repository on playframework.com is just for Play 1.x. So Mongo Module is not an option for you.
I am the author of ReactiveMongo-Extensions and it is highly inspired from MongoHelper. You can use which one you want. If you choose ReactiveMongo-Extensions JsonDao is your friend. There is also an example application which you can check out: https://github.com/mertkavi/play-reactivemongo-extensions-sample
BTW I am currently developing a newer driver from scratch. You may also give it a try: https://github.com/fehmicansaglam/tepkin

ReactiveMongo & JSON4S

I'm using JSON4S to parse some JSON strings I'm getting from external APIs.
Is there anyway to get JSON entities like there is with the play reactivemongo JSONCollection or the spray-json to reactive mongo converter in sprest?
Its easy to use JSON4S with the standard Mongo Casbah lib e.g. builder.insert(JObjectParser.parse(obj))
But I really want to be able to do this with reactivemongo.
You can start by taking a look at how it's implemented in play-reactivemongo plugin (conversion between play's js reads/writes and reactivemongo's types) here.
I know this is an old question, but this is always the first thing that pops up when I google it.
I've begun working on a project that does this based on the Play Framework's plugin.
Check the issue tracker, because there are currently some problems that may make using it not an option.
https://github.com/Jacoby6000/Json4s-reactivemongo-compatibility

Resquest MongoDB with scala

I want to do an application in Scala, with a MongoDB database. I found some tutorials to use it with ReactiveMongo, I wrote my classes, but I want to test it and I don't understand how to do a simple request; to add a user for example, or find him.
What is the right method to use?
You could use the Activate framework. It supports ReactiveMongo with a simple usage interface for queries and modifications.
Using it, is also easy to switch to other types of databases, like postgre and mysql.
http://activate-framework.org/
It uses transparent persistence with efficient memory usage, providing a simpler persistence paradigm with high scalability. Take a look at http://databen.ch
Do you want ReactiveMongo or just want to use mongodb on scala. If it's the lastest, try http://mongodb.github.io/casbah/tutorial.html
Is what we use in our projects...

Should I use MongoDb module or morphia module or Casbah in play framework for MongoDb?

I am working on a play framework project with scala in which I want to have Scala domain classes (or even Java domain classes) using MongoDb as data store.
I want maximum performance while serving hundreds of thousands if not millions of requests per day.
Since both scala language and Play framework is adding new features by the month, what is the best answer in terms of latest production version of the modules mentioned in the question
and play framework 1.2.2, scala 0.9.1+ and scala language 2.8+?
for anyone stumbling upon this question and using playframwork 2.1.x or above I highly recommend taking a look at reactivemongo site and github project.
It's a mongodb scala driver that allows asynchronous db operations.
Great performance and mature enough for use in production.
At the time of writing this the current version is 0.9 and is being used by us in production without any problems.
I use Morphia module, a MongoDB integration for Play! 1.2.x
For scala I would suggest you have a look at https://github.com/novus/salat
I've written a play plugin for salat which you can find here https://github.com/leon/play-salat
Good luck!

Is Morphia based on Java driver for MongoDb and can it work if domain model is scala?

Is it based on mongoDb java driver ?
Can I use it when the domain model is scala program in version 1.2.2RC1+ of play framework?
Please note that questions that may have been answered before may not be relevant to play framework version 1.2.2RC1+.
If you are looking for a high level Java client for MongoDB, Give Kundera (https://github.com/impetus-opensource/Kundera) a try. It’s a JPA based client library for Cassandra, Hbase and MongoDB. There is a pretty good example here: https://github.com/impetus-opensource/Kundera/wiki/Getting-started
Morphia does run on top of/uses the mongodb java driver. All java ORM solutions do. I don't see why it would be a problem to run it in Scala. I have no experience with the "play framework".