Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 0.11.10 #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,38 @@ import reactivemongo.api.{ Cursor, QueryOpts }
import play.modules.reactivemongo.{
MongoController, ReactiveMongoApi, ReactiveMongoComponents
}
import play.modules.reactivemongo.json.collection.JSONCollection
import reactivemongo.play.json.collection.JSONCollection

class Application @Inject() (val reactiveMongoApi: ReactiveMongoApi)
extends Controller with MongoController with ReactiveMongoComponents {

// BSON-JSON conversions
import play.modules.reactivemongo.json._, ImplicitBSONHandlers._
import reactivemongo.play.json._

// Iteratees cursor
import reactivemongo.play.iteratees.cursorProducer

// let's be sure that the collections exists and is capped
val futureCollection: Future[JSONCollection] = {
val db = reactiveMongoApi.db
val collection = db.collection[JSONCollection]("acappedcollection")
val db = reactiveMongoApi.database
val coll = db.map(_.collection[JSONCollection]("acappedcollection"))

collection.stats().flatMap {
case stats if !stats.capped =>
// the collection is not capped, so we convert it
println("converting to capped")
collection.convertToCapped(1024 * 1024, None)
case _ => Future(collection)
}.recover {
// the collection does not exist, so we create it
case _ =>
println("creating capped collection...")
collection.createCapped(1024 * 1024, None)
}.map { _ =>
for {
collection <- coll
stats <- collection.stats()
_ <- {
if (!stats.capped) {
// the collection is not capped, so we convert it
println("converting to capped")
collection.convertToCapped(1024 * 1024, None)
} else Future.successful(collection)
} recover {
// the collection does not exist, so we create it
case _ =>
println("creating capped collection...")
collection.createCapped(1024 * 1024, None)
}
} yield {
println("the capped collection is available")
collection
}
Expand Down Expand Up @@ -73,15 +80,15 @@ class Application @Inject() (val reactiveMongoApi: ReactiveMongoApi)
.find(Json.obj())
// the cursor must be tailable and await data
.options(QueryOpts().tailable.awaitData)
.cursor[JsObject]
.cursor[JsObject]()

// ok, let's enumerate it
cursor.enumerate()
cursorProducer.produce(cursor).enumerator()
}
Enumerator.flatten(futureEnumerator)
}

// We're done!
(in, out)
in -> out
}
}
16 changes: 11 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import play.PlayImport.PlayKeys._

name := "reactivemongo-tailablecursors-demo"

version := "0.11.0"
val reactiveMongoVer = "0.11.10"

scalaVersion := "2.11.6"
version := reactiveMongoVer

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
"org.reactivemongo" %% "play2-reactivemongo" % reactiveMongoVer,
"org.reactivemongo" %% "reactivemongo-iteratees" % reactiveMongoVer
)

libraryDependencies ++= Seq(
"org.reactivemongo" %% "play2-reactivemongo" % "0.11.0.play24",
"org.specs2" %% "specs2-core" % "2.4.9" % "test",
"org.specs2" %% "specs2-junit" % "2.4.9" % "test"
"org.specs2" %% "specs2-core" % "2.4.9" % Test,
"org.specs2" %% "specs2-junit" % "2.4.9" % Test
)

routesGenerator := InjectedRoutesGenerator
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ resolvers ++= Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.0")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6")