reactivemongo

Play2 Framework/Scala/Specs2 - Do different FakeApplications share Singleton objects?

☆樱花仙子☆ 提交于 2019-12-05 22:32:34
I'm quite new to Play2 and Scala. I'm writing a simple application that uses ReactiveMongo plugin. I wrote a simple object to use as DAO object UserDAO { def db: reactivemongo.api.DB = ReactiveMongoPlugin.db def collection: JSONCollection = db.collection[JSONCollection]("users") collection.indexesManager.ensure(Index(List("name" -> IndexType.Ascending), unique = true)) def insert(User): Future[LastError] = { collection.insert(unit) } def findOne(query: JsObject): Future[Option[User]] = { collection.find(query).one[User] } def removeOne(query: JsObject): Future[LastError] = { collection.remove

Strange MongoError (with ReactiveMongo) when Play reloads application

扶醉桌前 提交于 2019-12-05 09:17:16
Very often, when Play reloads the application after a code change, I receive the following error: MongoError['The node set can not be reached! Please check your network connectivity.'] The MongoDB log looks like this: 2016-09-06T18:51:22.609+0200 I NETWORK [initandlisten] waiting for connections on port 27017 2016-09-06T18:53:49.916+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60559 #1 (1 connection now open) 2016-09-06T18:53:51.185+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60561 #2 (2 connections now open) 2016-09-06T18:53:51.196+0200 I NETWORK

No Json deserializer found for type Option[reactivemongo.bson.BSONObjectID]

痴心易碎 提交于 2019-12-05 02:51:00
I'm getting a: No Json deserializer found for type Option[reactivemongo.bson.BSONObjectID]. Try to implement an implicit Reads or Format for this type. When trying to deserialise my review object. Review: case class Review(override var id: Option[BSONObjectID] = None, override var createdAt: Option[DateTime] = None, override var updatedAt: Option[DateTime] = None, grade: Int, text: String, originIPAddress: Option[String], status: ReviewStatus, origin: ReviewOrigin, rId: Option[Long], userId: Option[Long] ) extends TemporalModel object Review { import mongo_models.enums.EnumFormat._ implicit

ReactiveMongo: How to convert BSON returned by FindAndModify to JSON

≡放荡痞女 提交于 2019-12-04 16:37:08
Here below is the code for updating a document with Mongo's FindAndModify : val selector = BSONDocument("id" -> "1234") val modifier = BSONDocument("$set" -> BSONDocument("email" -> "new@domain.com")) ReactiveMongoPlugin.db.command(FindAndModify( collection.name, selector, Update(modifier, false), false, None )).transform( success => success.map { s => // doesn't work... Json.fromJson[Seq[JsValue]](toJson(s)).map(for (item <- _) yield item).get }.getOrElse(List[JsValue]()), failure => failure match { case e: LastError => DaoServiceException(e.message, Some(DATABASE_ERROR)) } ) In the success

Play: How to transform JSON while writing/reading it to/from MongoDB

狂风中的少年 提交于 2019-12-04 07:59:55
问题 Here is an simple JSON I want to write/read to/from MongoDB: { "id": "ff59ab34cc59ff59ab34cc59", "name": "Joe", "surname": "Cocker" } Before storing it in MongoDB, "ff59ab34cc59ff59ab34cc59" has to be transformed into an ObjectID and id renamed to _id ... so given the following Reads , how do I achieve that? val personReads: Reads[JsObject] = ( (__ \ 'id).read[String] ~ // how do I rename id to _id AND transform "ff59ab34cc59ff59ab34cc59" to an ObjectID? (__ \ 'name).read[String] ~ (__ \

Play2 + ReactiveMongo 实现一个活动报名应用

匆匆过客 提交于 2019-12-03 15:40:35
Play 2: https://playframework.com ReactiveMongo: http://reactivemongo.org 代码在: http://git.oschina.net/socialcredits/social-credits-activity-service 公司要做一些活动,需要一个线上的活动报名应用。想着前几天刚好看了下 ReactiveMongo ,觉得这个小应用正好练练手。 这个活动应用的功能非常简单:用户在线填写表单,提交表单,后台存储数据并向指定的专员发送邮箱通知。 Play 项目 整个项目目录结构如下: ├── app │ ├── controllers │ │ └── inapi │ ├── utils │ └── views │ └── activity ├── conf ├── data │ └── src │ └── main ├── platform │ └── src │ └── main ├── project ├── static │ └── src │ └── site └── util └── src ├── main app 、 conf 都是 Play 的标准目录,分别放置代码文件和项目配置文件。 app.views 包下的是Play的模板页面文件。 static 是用于放置前端源文件的,包括: js 、

How is ReactiveMongo implemented so that it is considered non-blocking?

帅比萌擦擦* 提交于 2019-12-03 03:11:08
Reading the documentation about the Play Framework and ReactiveMongo leads me to believe that ReactiveMongo works in such a way that it uses few threads and never blocks. However, it seems that the communication from the Play application to the Mongo server would have to happen on some thread somewhere . How is this implemented? Links to the source code for Play, ReactiveMongo, Akka, etc. would also be very appreciated. The Play Framework includes some documentation about this on this page about thread pools . It starts off: Play framework is, from the bottom up, an asynchronous web framework.

Akka and ReactiveMongo

怎甘沉沦 提交于 2019-12-02 21:06:04
I am trying to find the best approach to sharing the same pool of connection between actors withing the cluster workers. I have the following structure: Master Actor -> Worker Actors(can be up to 100 or more) -> MongoDB Between workers and MongoDB I want to put reactivemongo, however I am not sure how exactly to provide connection pool sharing between all actors. According to reactivemongo documentation: A MongoDriver instance manages an actor system; a connection manages a pool of connections. In general, MongoDriver or create a MongoConnection are never instantiated more than once. You can

Play: How to transform JSON while writing/reading it to/from MongoDB

这一生的挚爱 提交于 2019-12-02 20:49:19
Here is an simple JSON I want to write/read to/from MongoDB: { "id": "ff59ab34cc59ff59ab34cc59", "name": "Joe", "surname": "Cocker" } Before storing it in MongoDB, "ff59ab34cc59ff59ab34cc59" has to be transformed into an ObjectID and id renamed to _id ... so given the following Reads , how do I achieve that? val personReads: Reads[JsObject] = ( (__ \ 'id).read[String] ~ // how do I rename id to _id AND transform "ff59ab34cc59ff59ab34cc59" to an ObjectID? (__ \ 'name).read[String] ~ (__ \ 'surname).read[String] ) reduce And of course, I also need the contrary for my Writes , i.e. renaming _id

How to use ReactiveMongo + JSON aggregation framework in Play Framework?

谁说胖子不能爱 提交于 2019-12-02 09:54:04
问题 I need to utilize MongoDB's aggregation framework using ReactiveMongo. I only find this example which uses BSON. I would like to use JSON so I changed the code to : def populatedStates(col: JSONCollection) = { import col.BatchCommands.AggregationFramework.{AggregationResult, Group, Match, SumField} val res: Future[AggregationResult] = col.aggregate( Group(JsString("$state"))("totalPop" -> SumField("population")), List(Match(JSONDocument("totalPop" -> JSONDocument("$gte" -> 10000000L))))) res