简体   繁体   English

使用MongoDB播放Framework 2 Scala

[英]Play framework 2 scala with MongoDB

I am new in play framework 2. I have play 2 with scala and MongoDb requirement. 我是Play框架2的新手。我具有Scala和MongoDb要求的第二个游戏。 I searched lots on Play 2 and MongoDb connection, but didn't find any useful documentation. 我在Play 2和MongoDb连接上搜索了很多内容,但没有找到任何有用的文档。

There is lots of plugins available eg. 有很多可用的插件,例如。 Casbah, Reactive Mongo, Salat. 卡斯巴(Casbah),反应灵敏的蒙古(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? 如果我想在不使用第三方插件的情况下实现自己与Mongo的连接,这可能吗?

Please give examples and document on Play 2 and MongoDB connection. 请提供有关Play 2和MongoDB连接的示例和文档。

I suggest using ReactiveMongo as its non-blocking approach is similar to how Play itself works. 我建议使用ReactiveMongo,因为它的非阻塞方法类似于Play本身的工作方式。 The API works with scala Futures which is aa really nice fit with Play's Async actions. 该API可与Scala Futures配合使用,非常适合Play的Async操作。 You can also use their macros to convert case classes straight to BSON sparing quite some boilerplate code. 您还可以使用它们的宏将案例类直接转换为BSON,而无需花费很多样板代码。

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. 很多时间过去了,但是我想与那些分享他们的更新,他们可能会为Play Framework搜索Scala MongoDB客户端库。

Reactive Mongo is great but still lacks Play Framework 2.4 integration and MongoDB 3.0. 反应性Mongo很棒,但是仍然缺少Play Framework 2.4集成和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. 我们等待了很长时间,因此编写了一个库,该库以Scala样式包装了原始的MongodDB客户端,并且类似于api中的Reactive Mongo。 Take a look at https://github.com/evojam/play-mongodb-driver . 看看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. 使用Play Framework模块,它的启动非常简单,例如几分钟即可获得工作代码。

This way MongoDB is nice and easy to use in Scala. 这样,MongoDB在Scala中非常好用。 We have provided a comparison of the sample query execution is in our blog post about the driver on site. 我们在有关站点驱动程序的博客文章中提供了示例查询执行的比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM