Last active
January 5, 2017 09:59
-
-
Save gstraymond/085364ec85034bd64fa69e636c7231d2 to your computer and use it in GitHub Desktop.
play mongo bson - HomeController.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ai.snips.bsonmacros.DatabaseContext | |
import models.{SampleData, SampleDataDAO} | |
import org.mongodb.scala.bson.BsonObjectId | |
import play.api.Logger | |
import play.api.mvc._ | |
import scala.concurrent.ExecutionContext | |
class HomeController @Inject()(sampleDataDAO: SampleDataDAO, | |
dbContext: DatabaseContext) | |
(implicit ec: ExecutionContext) extends Controller { | |
def index = Action.async { | |
val data = SampleData(BsonObjectId(), "sample", boolean = false, (Math.random() * 10).toInt) | |
for { | |
// insert document | |
_ <- sampleDataDAO.insertOne(data) | |
// retrieving all documents | |
all <- sampleDataDAO.all.toFuture() | |
} yield { | |
Ok(s"${all.map(_.int)}") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment