Sørg for at du har korrekte konfigurationer i application.conf
play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoModule"
mongodb.uri = "mongodb://localhost:27017/demodb"
Du skal injicere og ændre mongo-koden som nedenfor
class MongoUserDao @Inject() (val reactiveMongoApi: ReactiveMongoApi)
extends UserDao {
// val users = reactiveMongoApi.db.collection[JSONCollection]("users") -- old API
// def find(userId:UUID):Future[Option[User]] =
// users.find(Json.obj("id" -> userId)).one[User] -- old code
def usersF = reactiveMongoApi.database.map(_.collection[JSONCollection]("users")) //new API
def find(userId:UUID):Future[Option[User]] = for {
users <- usersF
user <- users.find(Json.obj("id" -> userId)).one[User]
} yield user // new code
}
Hvis du sammenligner ny api-kode med gammel api-kode, returnerer reactiveMongoApi.database.map Future[Collection].