Zorg ervoor dat je de juiste configuraties hebt in application.conf
play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoModule"
mongodb.uri = "mongodb://localhost:27017/demodb"
U moet de mongo-code injecteren en wijzigen zoals hieronder
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
}
Als u nieuwe api-code vergelijkt met oude api-code, retourneert reactiveMongoApi.database.map Future[Collection].