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
Related
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
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.
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...
Hey I love Play Framework Scala and I also am falling in love with Firebase. I was wondering though, I'm planning on building an app using AngularFire and I'm going to need to do some server-side logic/computation and make some server-side queries to Firebase. Is this possible to do with a Play Framework Scala setup? If so what is the recommended approach? If not, is it coming? If so when? I think it's so cool that the Firebase guys used Scala to build Firebase, but I'm bummed there is no Scala API to work with (that I can see). Maybe I could use the Java API somehow, but write still write the app in Scala? Any help would be great. Thanks!
Scala is highly interoperable with Java (compiles to the same bytecode) so you should be able to use the Java API straight-up without any issues.
While some libraries add Scala-specific wrappers to make an API more idiomatic and pleasant for a functional programming style and to smooth some rough edges, it's often not strictly necessary.
If for some reason you didn't want to use the Java client libs, you could also interface with the Firebase REST API via Play 2's very convenience and succinct web services library.
Should be no problem with either their Java SDK (when using Firebase on the backend) or the JavaScript SDK (when using it on the client). But you won't have native support for Scala or Play, especially no support for Iteratee/Enumeratee in Play.
The Java API looks quite good and seems to be event driven. So it should be no problem to integrate it in Play in a scalable way.
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!