BSONDocumentReader factories
- Companion:
- class
Value members
Concrete methods
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.
'''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")
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)
}
'''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))
'''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:
'''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:
'''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: