2016-07-08 3 views
0
name := """sample""" 

version := "1.0-SNAPSHOT" 

lazy val root = (project in file(".")).enablePlugins(PlayScala) 

scalaVersion := "2.11.8" 

resolvers ++= Seq(
    "Atlassian Releases" at "https://maven.atlassian.com/public/", 
    "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases", 
    Resolver.sonatypeRepo("snapshots") 
) 

pipelineStages := Seq(digest,gzip) 

libraryDependencies ++= Seq(
    cache, 
    filters, 
    "com.typesafe.play" %% "play-mailer" % "3.0.1", 
    "com.mohiva" %% "play-silhouette" % "3.0.0", 
    "org.webjars" %% "webjars-play" % "2.4.0", 
    "net.codingwell" %% "scala-guice" % "4.0.0", 
    "net.ceedubs" %% "ficus" % "1.1.2", 
    "com.adrianhurt" %% "play-bootstrap3" % "0.4.4-P24", 
    "com.mohiva" %% "play-silhouette-testkit" % "3.0.0" % "test", 
    "org.reactivemongo" %% "play2-reactivemongo" % "0.11.14-play24", 
    "org.reactivemongo" %% "reactivemongo-play-json" % "0.11.14", 
    specs2 % Test 
) 

routesGenerator := InjectedRoutesGenerator 

scalacOptions ++= Seq(
    "-encoding", "UTF-8", 
    "-deprecation", 
    "-feature", 
    "-unchecked", 
    "-Xfatal-warnings", 
    "-Xlint", 
    "-Ywarn-adapted-args", 
    "-Ywarn-dead-code", 
    "-Ywarn-inaccessible", 
    "-Ywarn-nullary-override", 
    "-Ywarn-value-discard", 
    "-language:reflectiveCalls" 
) 

-ControllerSymbol JSONCollection wird in scala Spiel veraltet und reactiveMongodb

package controllers 

import javax.inject.{Inject, Singleton} 

import play.api.Logger 
import play.api.libs.concurrent.Execution.Implicits.defaultContext 
import play.api.libs.json.Json 
import play.api.mvc.{Action, Controller} 
import play.modules.reactivemongo.json.collection.JSONCollection 
import play.modules.reactivemongo.{MongoController, ReactiveMongoApi, ReactiveMongoComponents} 
import reactivemongo.api.collections.bson.BSONCollection 
import reactivemongo.api.commands.bson.BSONCountCommand.{ Count, CountResult } 
import reactivemongo.api.commands.bson.BSONCountCommandImplicits._ 
import reactivemongo.bson.BSONDocument 

import scala.concurrent.Future 

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

    def jsonCollection = reactiveMongoApi.database.collection[JSONCollection]("deals"); 
    def bsonCollection = reactiveMongoApi.database.collection[BSONCollection]("deals"); 

    //initiate the sample data for deal 
    def index = Action { 
    Logger.info("Application startup...") 

    val posts = List(
     Json.obj(
     "name" -> "ABC", 
     "description" -> "Alphabet", 
     "author" -> "Steve" 
    ), 


    ) 

    val query = BSONDocument("name" -> BSONDocument("$exists" -> true)) 
    val command = Count(query) 
    val result: Future[CountResult] = bsonCollection.runCommand(command) 

    result.map { res => 
     val numberOfDocs: Int = res.value 
     if(numberOfDocs < 1) { 
     jsonCollection.bulkInsert(posts.toStream, ordered = true).foreach(i => Logger.info("Record added.")) 
     } 
    } 

    Ok("Your database is ready.") 
    } 
    // use for cleaning dummy data 
    def cleanup = Action { 
    jsonCollection.drop().onComplete { 
     case _ => Logger.info("Database collection dropped") 
    } 
    Ok("Your database is clean.") 
    } 
} 

ich Fehler:

enter image description here

Antwort

2

Sieht aus wie JSONCollection kann in zwei verschiedenen Orten.

http://reactivemongo.org/releases/0.11/play-api/index.html#play.modules.reactivemongo.json.collection.JSONCollection http://reactivemongo.org/releases/0.11/json-api/index.html#reactivemongo.play.json.collection.JSONCollection

sicher, dass Sie von der rechten dep importieren (was ich denke, ist "org.reactivemongo" %% "reactivemongo-play-json" % "0.11.14"))

+0

Warum würden Sie eine ältere Version verwenden? – mfirry

+0

http://reactivemongo.org/releases/0.11/documentation/json/overview.html – mfirry

+0

ja, weil ich das bekomme: Methode db in Merkmal ReactiveMongoApi ist veraltet: Verwenden Sie [[Datenbank]] – kn3l

Verwandte Themen