Type safe Scala DSL for MongoDB, that has 3 simple goals:
- Type-safety. Prevent runtime exceptions by allowing only BSON types or types that can be converted to BSON.
- Fix the Java driver's UUID bug in a backwards compatible manner.
- Keep syntax close to original Javascript
Basic example:
import mongolia._
import BsonCodecs._
val personId = new ObjectId
val person = obj(
_id(personId), // equivalent to "_id" := personId
"name" := obj(
"first" := "Francis",
"middle" := "Joseph",
"last" := "Underwood"
),
"titles" := arr("Majority Whip", "Vice-president", "President")
)
coll.insert(person)
coll.findOpt(_id(personId)) match {
case None => sys.error(s"Not found: $personId")
case Some(person) =>
val firstName: String = person("name.first").as[String]
val middleName: Option[String] = person("name.middle").opt[String]
val lastName: String = person("name.last").as[String]
val titles: List[String] = person("titles").asList[String]