BSONDocumentWriter factories.
- Companion:
- class
Value members
Concrete methods
Creates a BSONDocumentWriter based on the given write
function.
This function is called within a scala.util.Try.
Creates a BSONDocumentWriter based on the given write
function.
This function is called within a scala.util.Try.
import reactivemongo.api.bson.{ BSONDocument, BSONDocumentWriter }
case class Foo(value: String)
val foo: BSONDocumentWriter[Foo] =
BSONDocumentWriter { (f: Foo) => BSONDocument("value" -> f.value) }
Creates a BSONDocumentWriter based on the given partial function.
Creates a BSONDocumentWriter based on the given partial function.
A exceptions.ValueDoesNotMatchException is returned as Failure
for any value that is not matched by the write
function.
import reactivemongo.api.bson.{ BSONDocument, BSONDocumentWriter }
case class Foo(value: String)
val writer = BSONDocumentWriter.collect[Foo] {
case Foo(value) if value.nonEmpty =>
BSONDocument("value" -> value)
}
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter based on the given
partially safe write
function.
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter based on the given
partially safe write
function.
A exceptions.ValueDoesNotMatchException is returned as Failure
for any value that is not matched by the write
function.
import reactivemongo.api.bson.{ BSONDocument, BSONDocumentWriter }
case class Foo(value: String)
val writer = BSONDocumentWriter.collectFrom[Foo] {
case Foo(value) if value.nonEmpty =>
scala.util.Success(BSONDocument("value" -> value))
}
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes a single value as a BSONDocument with a single field.
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes a single value as a BSONDocument with a single field.
- Value parameters:
- name
the name of the field to be written
import reactivemongo.api.bson.BSONDocumentWriter val writer = BSONDocumentWriter.field[String]("foo") writer.writeTry("bar") // => Success: {'foo': 'bar'}
Creates a BSONDocumentWriter based on the given write
safe function.
Creates a BSONDocumentWriter based on the given write
safe function.
import scala.util.Success
import reactivemongo.api.bson.{ BSONDocument, BSONDocumentWriter }
case class Foo(value: String)
val writer = BSONDocumentWriter.from[Foo] { foo =>
Success(BSONDocument("value" -> foo.value))
}
- Value parameters:
- write
the safe function to write
T
values as BSON
Creates a BSONWriter based on the given write
function.
Creates a BSONWriter based on the given write
function.
import reactivemongo.api.bson.{ BSONDocument, BSONDocumentWriter }
case class Foo(value: String)
val writer = BSONDocumentWriter.option[Foo] { foo =>
Some(BSONDocument("value" -> foo.value))
}
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes tuple elements as BSONDocument fields.
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes tuple elements as BSONDocument fields.
import reactivemongo.api.bson.BSONDocumentWriter
val writer = BSONDocumentWriter.tuple2[String, Int]("name", "age")
writer.writeTry("Foo" -> 20)
// => Success: {'name': 'Foo', 'age': 20}
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes tuple elements as BSONDocument fields.
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes tuple elements as BSONDocument fields.
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes tuple elements as BSONDocument fields.
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes tuple elements as BSONDocument fields.
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes tuple elements as BSONDocument fields.
'''EXPERIMENTAL:''' Creates a BSONDocumentWriter that writes tuple elements as BSONDocument fields.