Play Framework 2.2 Java with MongoDB - mongodb

what's the best way to use MongoDB with PlayFramework 2.2 Java? Is there one that allows me to use the javax.persistence.Entity annotation?
Thanks!

What about an ORM for Mongodb ?
Reading this http://www.infoq.com/articles/mongodb-java-orm-bcd
I never used it but it seems that MJORM could do what you want :
http://code.google.com/p/mongo-java-orm/source/browse/trunk/src/main/java/com/googlecode/mjorm/?r=3180

Related

How to read and write from MongoDb using two different drivers (MongoDB Scala Driver and Salat)

We want to change our MongoDB driver overtime to MongoDB Scala Driver, but we using Salat and it reads and writes sealed classes and ADTs using "_typeHint" to the DB. The MongoDB Scala Driver reads and writes sealed classes and ADTs using "_t", What we want is a way to read and write "_typeHint" using MongoDB Scala Driver? We know we need a custom codec, but not sure how to implement it.
We want the ability to support both drivers until we remove Salat.
Thanks.
This appears to be described here. See "annotation convention" and "bson discriminator".

Can ReactiveMongo can be used in Lagom framework?

I need to convert a existing Play + Scala + Mongodb application into Lagom micro services. But all the examples I have tested were using Cassadra.
There is Read Support for mongodb, as mentioned in their documentation.
There is plugin too.
This means, can we not write into mongodb collections?
Yes, you notionally can create a MongoDB persistence API. You'll need to implement:
com.lightbend.lagom.scaladsl.persistence.{
PersistenceComponents,
PersistentEntityRegistry,
ReadSidePersistenceComponents,
WriteSidePersistenceComponents
}
and play.api.db.DBComponents.
You can see an example implementation here for JDBC.

MongoDB document to POJO

I'm using allanbank async driver for operations on mongodb. Is there any api available through which I can convert returned Document to a POJO, like we can do in spring driver available for mongodb
You could use morphia (which would mean using mongodb's java driver, or you could use jackson to map back to your POJOs.
You can use Spring Data , it includes integrated object mapping between documents and POJOs.
I wanted something for async driver as well. As MongoDB came with Codec Feature in 3.0 version (both sync and async version of driver), it's not neccessary to use libraries such as Morphia anymore so I wrote simple library for mapping POJO into MongoDB myself.
in Spring Data MongoDB you can use
#Autowired
MongoConverter mongoConverter;
Then
TARGET_OBJECT = mongoConverter.read(YOUR_TARGET.class, YOUR_DOCUMENT);

mongodb persistence patterns for JSON client app, jackson mapper or morphia driver?

I've started a new job where they are using mongodb in a java environment.
They have implemented a pattern using DTOs and factories with the morphia driver, this may be due to a migration onto mongodb from a key value store previously. The client is a JSON client.
It seems to me that the jackson-mongo-mapper would be a better approach because it's just mapping pojos from json to BSON and back, seems like it could do away with all DTO factory facade?
Anyone know any pros and cons with these different approaches?
Spring Data for Mongodb is very nice since you can use even another data store or mix them and repository interface is very helpful.
Kundera is an option through JPA2
http://agilemobiledeveloper.wordpress.com/2013/08/22/working-with-mongodb-using-kundera/
There's a lot of java to mongodb options.
http://www.agilemobiledeveloper.com/2013/01/31/hibernate-ogm-mongodb-vs-kundera-vs-jongo-vs-mongodb-api-vs-morphia-vs-spring-data-mongo-mongodb-drivers-for-java/
Adding your own data layer and making sure you use DI and test it fully is very helpful.
NOSQLUnit is awesome -> https://github.com/lordofthejars/nosql-unit
DTOs are good for keeping a separation between implementation and design, so when they need or want to switch from mongo to some other NoSQL or SQL database it can be done cleanly.

Silex and MongoDB, which Silex Extension

I would like to use Silex with MongoDB.
I guess the best way is to use a Silex Extension that again uses the Doctrine MongoDB libs.
There are two Silex Extensions right now that seem to provide this functionality.
https://github.com/fate/Silex-Extensions
and
https://github.com/docteurklein/SilexExtensions
Except that the first brings more other Extensions and the second uses submodules (which i would prefer) instead of vendors.sh, are there more things to take care of?
Can anybody recommend the one or the other?
Update:
The Extensions below are outdated, pls use answer above.
to answer it myself:
https://github.com/fate/Silex-Extensions uses the Doctrine MongoDB Abstraction Layer
whereas
https://github.com/docteurklein/SilexExtensions uses the Doctrine MongoDB ODM (Object Document Mapper)
So with the first you can only query MongoDB through Doctrine and with the second you can persist Model Objects to MongoDB as known from f.e. symfony models.
This are brand new MongoDB providers with multi connection support.
MongoDB:
https://github.com/saxulum/saxulum-doctrine-mongodb-provider
MongoDB ODM:
https://github.com/saxulum/saxulum-doctrine-mongodb-odm-provider