Skip to content

nilskp/mongolia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Scala version Download Join the chat at https://gitter.im/nilskp/mongolia

Mongolia

Type safe Scala DSL for MongoDB, that has 3 simple goals:

  1. Type-safety. Prevent runtime exceptions by allowing only BSON types or types that can be converted to BSON.
  2. Fix the Java driver's UUID bug in a backwards compatible manner.
  3. 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]

About

Scala DSL for MongoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages