reactivemongo

Play + ReactiveMongo: capped collection and tailable cursor

*爱你&永不变心* 提交于 2019-12-25 06:13:04
问题 I'm using Play Framework with Scala, Akka and ReactiveMongo. I want to use a collection in MongoDB as a circular queue. Several actors can insert documents into it; one actor retrieves these documents as soon as they're available (a sort of publish-subscribe system). I'm using capped collections and tailable cursor. Everytime I retrieve some documents I have to run the command EmptyCapped to flush the capped collection (it's not possible to REMOVE elements from it) otherwise I retrieve always

Play + ReactiveMongo: capped collection and tailable cursor

本秂侑毒 提交于 2019-12-25 06:11:16
问题 I'm using Play Framework with Scala, Akka and ReactiveMongo. I want to use a collection in MongoDB as a circular queue. Several actors can insert documents into it; one actor retrieves these documents as soon as they're available (a sort of publish-subscribe system). I'm using capped collections and tailable cursor. Everytime I retrieve some documents I have to run the command EmptyCapped to flush the capped collection (it's not possible to REMOVE elements from it) otherwise I retrieve always

ReactiveMongo: single connection pool instance Vs many connection pool instances Vs multiple connection pools

旧街凉风 提交于 2019-12-24 22:52:06
问题 I am using ReactiveMongo 0.12, and trying to understand the core differences between how different types of connection pooling works in ReactiveMongo. ReactiveMongo seems to provide 3 ways in which we can establish connection with the database: TYPE 1: Using Single Connection Pool Instance import reactivemongo.api.MongoConnection val driver1 = new reactivemongo.api.MongoDriver val connection3 = driver1.connection(List("addressA: 27017", "addressB: 27017","addressC": 27017", "addressD: 27017")

Comma separated list with Enumerator

可紊 提交于 2019-12-24 07:38:05
问题 I've just started working with Scala in my new project (Scala 2.10.3, Play2 2.2.1, Reactivemongo 0.10.0), and encountered a pretty standard use case, which is - stream all the users in MongoDB to the external client. After navigating Enumerator, Enumeratee API I have not found a solid solution for that, and so I solved this in following way: val users = collection.find(Json.obj()).cursor[User].enumerate(Integer.MAX_VALUE, false) var first:Boolean = true val indexedUsers = (users.map(u => { if

ReactiveMongo ConnectionNotInitialized In Test After Migrating to Play 2.5

倖福魔咒の 提交于 2019-12-24 05:44:23
问题 After migrating my Play (Scala) app to 2.5.3, some tests of my code using ReactiveMongo that once passed now fail in the setup. Here is my code using ScalaTest: def fixture(testMethod: (...) => Any) { implicit val injector = new ScaldiApplicationBuilder() .prependModule(new ReactiveMongoModule) .prependModule(new TestModule) .buildInj() def reactiveMongoApi = inject[ReactiveMongoApi] def collection: BSONCollection = reactiveMongoApi.db.collection[BSONCollection](testCollection) lazy val id =

Get the return value of reactivemongo findAndUpdate function

核能气质少年 提交于 2019-12-23 05:07:28
问题 I call the findAndUpdate function on a mongo collection to increase a counter, and I want to get the value of the counter for further use.Here is my code: collection.findAndUpdate( BSONDocument("name" -> "counter"), BSONDocument("$inc" -> BSONDocument("count" -> 1)), fetchNewObject = true, upsert = true ).map{ e => println("count = " + e.value.getAs[Int]("count")) //I want to do something with the count here } This doesn't compile because e.value.getAs[Int]("count") seems to be wrong. The

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

孤者浪人 提交于 2019-12-22 04:03:12
问题 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:

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

允我心安 提交于 2019-12-20 12:34:23
问题 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

Akka and ReactiveMongo

随声附和 提交于 2019-12-20 10:08:13
问题 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

How to convert JSON String to a BSONDocument

纵饮孤独 提交于 2019-12-19 04:51:08
问题 I have the following function that uses the reactivemongo driver and actually does a good job writing to the database. def writeDocument() = { val document = BSONDocument( "firstName" -> "Stephane", "lastName" -> "Godbillon", "age" -> 29) val future = collection.insert(document) future.onComplete { case Failure(e) => throw e case Success(result) => { println("successfully inserted document with result = " + result) } } } But the limitation of that function is that the JSON is hardcoded into a