Reactive Scala Driver for MongoDB

Asynchronous & Non-Blocking

BSON extra libraries

Some extra libraries are provided along to ease the BSON integration.

GeoJSON

A new GeoJSON library is provided, with the geometry types and the corresponding handlers to read from and write them to appropriate BSON representation.

It can be configured in the build.sbt as below.

libraryDependencies += "org.reactivemongo" %% "reactivemongo-bson-geo" % "1.1.0-RC12"

Then the GeoJSON types can be imported and used:

import reactivemongo.api.bson._

// { type: "Point", coordinates: [ 40, 5 ] }
val geoPoint = GeoPoint(40, 5)

// { type: "LineString", coordinates: [ [ 40, 5 ], [ 41, 6 ] ] }
val geoLineString = GeoLineString(
  GeoPosition(40D, 5D, None),
  GeoPosition(41D, 6D))

More GeoJSON examples

GeoJSON ReactiveMongo Description
Position GeoPosition Position coordinates
Point GeoPoint Single point with single position
LineString GeoLineString Simple line
LinearRing GeoLinearRing Simple (closed) ring
Polygon GeoPolygon Polygon with at least one ring
MultiPoint GeoMultiPoint Collection of points
MultiLineString GeoMultiLineString Collection of LineString
MultiPolygon GeoMultiPolygon Collection of polygon
GeometryCollection GeoGeometryCollection Collection of geometry objects

See Scaladoc

Monocle

(Experimental)

The library that provides Monocle based optics, for BSON values.

It can be configured in the build.sbt as below.

libraryDependencies += "org.reactivemongo" %% "reactivemongo-bson-monocle" % "1.1.0-RC12"

Then the utilities can be imported and used:

import reactivemongo.api.bson._

import reactivemongo.api.bson.monocle._ // new library

val barDoc = BSONDocument(
  "lorem" -> 2,
  "ipsum" -> BSONDocument("dolor" -> 3))

val topDoc = BSONDocument(
  "foo" -> 1,
  "bar" -> barDoc)

// Simple field
val lens1 = field[BSONInteger]("foo")
val updDoc1: BSONDocument = lens1.set(BSONInteger(2))(topDoc)
// --> { "foo": 1, ... }

// Nested field
val lens2 = field[BSONDocument]("bar").
  composeOptional(field[Double]("lorem"))

val updDoc2 = lens2.set(1.23D)(topDoc)
// --> { ..., "bar": { "lorem": 1.23, ... } }

More monocle examples

See Scaladoc

Specs2

The Specs2 library provides utilities to write tests using specs2 with BSON values.

It can be configured in the build.sbt as below.

libraryDependencies += "org.reactivemongo" %% "reactivemongo-bson-specs2" % "1.1.0-RC12"
import reactivemongo.api.bson.BSONDocument
import reactivemongo.api.bson.specs2._

final class MySpec extends org.specs2.mutable.Specification {
  "Foo" title

  "Bar" should {
    "lorem" in {
      BSONDocument("ipsum" -> 1) must_=== BSONDocument("dolor" -> 2)
      // Use provided Diffable to display difference
      // between actual and expected documents
    }
  }
}

More specs2 examples

See Scaladoc

Suggest changes