Skip to content

Instantly share code, notes, and snippets.

@josdirksen
Created January 31, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josdirksen/91d24ac1f632e2ae269f to your computer and use it in GitHub Desktop.
Save josdirksen/91d24ac1f632e2ae269f to your computer and use it in GitHub Desktop.
Database.scala
import reactivemongo.api._
import reactivemongo.api.collections.default.BSONCollection
import reactivemongo.bson.BSONDocument
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
object Database {
val collection = connect()
def connect(): BSONCollection = {
val driver = new MongoDriver
val connection = driver.connection(List("localhost"))
val db = connection("akka")
db.collection("stocks")
}
def findAllTickers(): Future[List[BSONDocument]] = {
val query = BSONDocument()
val filter = BSONDocument("Company" -> 1, "Country" -> 1, "Ticker" -> 1)
// which results in a Future[List[BSONDocument]]
Database.collection
.find(query, filter)
.cursor[BSONDocument]
.collect[List]()
}
def findTicker(ticker: String) : Future[Option[BSONDocument]] = {
val query = BSONDocument("Ticker" -> ticker)
Database.collection
.find(query)
.one
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment