BSONDocumentReader

Companion:
class
class Object
trait Matchable
class Any

Value members

Concrete methods

def apply[T](read: BSONDocument => T): BSONDocumentReader[T]

Creates a BSONDocumentReader based on the given read function.

Creates a BSONDocumentReader based on the given read function.

import reactivemongo.api.bson.BSONDocumentReader

case class Foo(name: String, age: Int)

val fooReader: BSONDocumentReader[Foo] = BSONDocumentReader[Foo] { doc =>
 (for {
   nme <- doc.string("name")
   age <- doc.int("age")
 } yield Foo(nme, age)).getOrElse(Foo("unknown", -1))
}

'''EXPERIMENTAL:''' Creates a BSONDocumentReader based on the given partial function.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader based on the given partial function.

def field[T](name: String)(implicit r: BSONReader[T]): BSONDocumentReader[T]

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads a single document field.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads a single document field.

Value parameters:
name

the name of the field to be read

import reactivemongo.api.bson.{ BSONDocument, BSONDocumentReader }
val reader = BSONDocumentReader.field[String]("foo")
val doc = BSONDocument("foo" -> "bar")
reader.readTry(doc) // Success("bar")
def from[T](read: BSONDocument => Try[T]): BSONDocumentReader[T]

Creates a BSONDocumentReader based on the given safe read function.

Creates a BSONDocumentReader based on the given safe read function.

import reactivemongo.api.bson.BSONDocumentReader

case class Foo(name: String, age: Int)

val fooReader: BSONDocumentReader[Foo] =
 BSONDocumentReader.from[Foo] { doc =>
   for {
     nme <- doc.getAsTry[String]("name")
     age <- doc.getAsTry[Int]("age")
   } yield Foo(nme, age)
 }

Creates a BSONDocumentReader based on the given read function.

Creates a BSONDocumentReader based on the given read function.

import reactivemongo.api.bson.BSONDocumentReader

case class Foo(name: String, age: Int)

val fooReader: BSONDocumentReader[Foo] =
 BSONDocumentReader.option[Foo] { doc =>
   for {
     nme <- doc.string("name")
     age <- doc.int("age")
   } yield Foo(nme, age)
 }
def tuple2[A : BSONReader, B : BSONReader](field1: String, field2: String): BSONDocumentReader[(A, B)]

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the specified document fields as tuple elements.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the specified document fields as tuple elements.

import reactivemongo.api.bson.{ BSONDocument, BSONDocumentReader }

val reader = BSONDocumentReader.tuple2[String, Int]("name", "age")

val doc = BSONDocument("name" -> "Foo", "age" -> 20)

reader.readTry(doc) // => Success(("Foo", 20))
def tuple3[A : BSONReader, B : BSONReader, C : BSONReader](field1: String, field2: String, field3: String): BSONDocumentReader[(A, B, C)]

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the specified document fields as tuple elements.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the specified document fields as tuple elements.

See also:
def tuple4[A : BSONReader, B : BSONReader, C : BSONReader, D : BSONReader](field1: String, field2: String, field3: String, field4: String): BSONDocumentReader[(A, B, C, D)]

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the specified document fields as tuple elements.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the specified document fields as tuple elements.

See also:
def tuple5[A : BSONReader, B : BSONReader, C : BSONReader, D : BSONReader, E : BSONReader](field1: String, field2: String, field3: String, field4: String, field5: String): BSONDocumentReader[(A, B, C, D, E)]

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the specified document fields as tuple elements.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the specified document fields as tuple elements.

See also: