Packages

package bson

BSON main API

import reactivemongo.api.bson._

// { "name": "Johny", "surname": "Doe", "age": 28, "months": [1, 2, 3] }
document ++ ("name" -> "Johny") ++ ("surname" -> "Doe") ++
("age" -> 28) ++ ("months" -> array(1, 2, 3))

// { "_id": generatedId, "name": "Jane", "surname": "Doe", "age": 28,
//   "months": [1, 2, 3], "details": { "salary": 12345,
//   "inventory": ["foo", 7.8, 0, false] } }
document ++ ("_id" -> generateId, "name" -> "Jane", "surname" -> "Doe",
  "age" -> 28, "months" -> array(1, 2, 3),
  "details" -> document(
    "salary" -> 12345L, "inventory" -> array("foo", 7.8, 0L, false)))

System properties:

The following properties can be set (e.g. using -D option).

  • reactivemongo.api.bson.bufferSizeBytes (integer; default: 96): Number of bytes used as initial size when allocating a new buffer.
  • reactivemongo.api.bson.document.strict (boolean; default: false): Flag to enable strict reading of document (filter duplicate fields, see BSONDocument).
Linear Supertypes
Utils, Aliases, DefaultBSONHandlers, BSONIdentityHandlers, BSONIdentityLowPriorityHandlers, LowPriority1BSONHandlers, LowPriority2BSONHandlers, LowPriority3BSONHandlers, LowPriority4BSONHandlers, LowPriorityBSONHandlersCompat, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. bson
  2. Utils
  3. Aliases
  4. DefaultBSONHandlers
  5. BSONIdentityHandlers
  6. BSONIdentityLowPriorityHandlers
  7. LowPriority1BSONHandlers
  8. LowPriority2BSONHandlers
  9. LowPriority3BSONHandlers
  10. LowPriority4BSONHandlers
  11. LowPriorityBSONHandlersCompat
  12. AnyRef
  13. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Package Members

  1. package exceptions

Type Members

  1. sealed abstract class BSONArray extends BSONValue

    A BSONArray (type 0x04) is a indexed sequence of BSONValue.

    A BSONArray (type 0x04) is a indexed sequence of BSONValue.

    import reactivemongo.api.bson._
    
    BSONArray(BSONString("foo"), BSONDouble(1.2D))
  2. abstract class BSONArrayCollectionReader[M[_], T] extends BSONReader[M[T]]
    Attributes
    protected
    Definition Classes
    LowPriority1BSONHandlers
  3. final class BSONBinary extends BSONValue

    A BSON binary value.

    A BSON binary value.

    import reactivemongo.api.bson.{ BSONBinary, Subtype }
    
    BSONBinary("foo".getBytes("UTF-8"), Subtype.GenericBinarySubtype)
  4. final class BSONBoolean extends BSONValue with Value

    BSON boolean value

  5. sealed trait BSONBooleanLike extends AnyRef

    A BSON value that can be seen as a boolean.

    A BSON value that can be seen as a boolean.

    Conversions:

    • number = 0 ~> false
    • number != 0 ~> true
    • boolean
    • undefined ~> false
    • null ~> false
    import scala.util.Success
    import reactivemongo.api.bson.{ BSONBooleanLike, BSONDocument, BSONInteger }
    
    val bi = BSONInteger(1)
    assert(bi.asTry[BSONBooleanLike].flatMap(_.toBoolean) == Success(true))
    
    val doc = BSONDocument("field" -> bi)
    assert(doc.getAsTry[BSONBooleanLike]("field").
      flatMap(_.toBoolean) == Success(true))
  6. final class BSONDateTime extends BSONValue with Value

    BSON date time value

  7. final class BSONDecimal extends BSONValue with Value with Value

    Value wrapper for a BSON 128-bit decimal.

  8. sealed abstract class BSONDocument extends BSONValue with ElementProducer with BSONDocumentLowPriority with BSONDocumentExperimental

    A BSONDocument structure (BSON type 0x03).

    A BSONDocument structure (BSON type 0x03).

    A BSONDocument is an unordered set of fields (String, BSONValue).

    Note: The insertion/initial order of the fields may not be maintained through the operations.

  9. type BSONDocumentHandler[T] = BSONDocumentReader[T] with BSONDocumentWriter[T] with BSONHandler[T]

    Convenient type alias for document handlers

  10. trait BSONDocumentReader[T] extends BSONReader[T]
  11. trait BSONDocumentWriter[T] extends BSONWriter[T]
  12. final class BSONDouble extends BSONValue with Value with Value

    A BSON Double.

    A BSON Double.

    reactivemongo.api.bson.BSONDouble(1.23D)
  13. sealed abstract class BSONElement extends ElementProducer

    BSON element, typically a pair of name and BSONValue.

    BSON element, typically a pair of name and BSONValue.

    import reactivemongo.api.bson.{ BSONElement, BSONString }
    
    BSONElement("name", BSONString("value"))
  14. trait BSONHandler[T] extends BSONReader[T] with BSONWriter[T]

    A BSON handler is able to both read and write T values from/to BSON representation.

    A BSON handler is able to both read and write T values from/to BSON representation.

    import scala.util.Try
    import reactivemongo.api.bson.{ BSONHandler, BSONValue }
    
    def roundtrip[T](value: T)(implicit handler: BSONHandler[T]): Try[Boolean] =
      for {
        bson: BSONValue <- handler.writeTry(value)
        dser <- handler.readTry(bson)
      } yield (dser == value) // true
  15. final class BSONInteger extends BSONValue with Value with Value

    BSON Integer value

  16. final class BSONJavaScript extends BSONValue

    BSON JavaScript value.

  17. final class BSONJavaScriptWS extends BSONValue

    BSON JavaScript value with scope (WS).

  18. final class BSONLong extends BSONValue with Value with Value

    BSON Long value

  19. sealed trait BSONMaxKey extends BSONValue

    BSON Max key value

  20. sealed trait BSONMinKey extends BSONValue

    BSON Min key value

  21. sealed trait BSONNull extends BSONValue with Value

    BSON null value

  22. sealed trait BSONNumberLike extends AnyRef

    A BSON value that can be seen as a number.

    A BSON value that can be seen as a number.

    Conversions:

    import scala.util.Success
    import reactivemongo.api.bson.{ BSONNumberLike, BSONDocument, BSONInteger }
    
    val bi = BSONInteger(1)
    assert(bi.asTry[BSONNumberLike].flatMap(_.toLong) == Success(1L))
    
    val doc = BSONDocument("field" -> bi)
    assert(doc.getAsTry[BSONNumberLike]("field").
      flatMap(_.toDouble) == Success(1D))
  23. sealed abstract class BSONObjectID extends BSONValue

    BSON ObjectId value.

    BSON ObjectId value.

    import scala.util.Try
    import reactivemongo.api.bson.BSONObjectID
    
    val oid: BSONObjectID = BSONObjectID.generate()
    
    val _: Try[BSONObjectID] = BSONObjectID.parse(oid.stringify)

    | Timestamp (seconds) | Machine identifier | Thread identifier | Increment

    | --- | --- | --- | ---

    | 4 bytes | 3 bytes | 2 bytes | 3 bytes

  24. trait BSONReader[T] extends AnyRef

    A reader that produces an instance of T from a subtype of BSONValue.

  25. final class BSONRegex extends BSONValue

    BSON Regex value.

  26. sealed trait BSONStrictDocument extends BSONStrictDocumentLowPriority

    EXPERIMENTAL: Strict documentation representation with at most one value per field name (no duplicate).

    EXPERIMENTAL: Strict documentation representation with at most one value per field name (no duplicate).

    import reactivemongo.api.bson.BSONDocument
    
    def strict1 = // { 'foo': 1 }
      BSONDocument.strict("foo" -> 1, "foo" -> 2)
    
    def strict2 = BSONDocument("foo" -> 1, "foo" -> 2).asStrict
    
    assert(strict1 == strict2)
  27. final class BSONString extends BSONValue

    A BSON string.

    A BSON string.

    reactivemongo.api.bson.BSONString("foo")
  28. final class BSONSymbol extends BSONValue

    BSON Symbol value.

  29. sealed abstract class BSONTimestamp extends BSONValue with Value

    BSON Timestamp value

  30. sealed trait BSONUndefined extends BSONValue with Value

    BSON undefined value

  31. sealed trait BSONValue extends AnyRef

    A BSON value

  32. trait BSONWriter[T] extends AnyRef

    A writer that produces a subtype of BSONValue from an instance of T.

  33. type BaseColl[T] = Iterable[T]
    Definition Classes
    Aliases
  34. sealed trait ElementProducer extends Producer[BSONElement]

    See BSONDocument

  35. trait FieldNaming extends (String) => String

    Naming strategy, to map each class property to the corresponding field.

  36. trait KeyReader[T] extends AnyRef

    Mapping from a BSON string to T

  37. trait KeyWriter[T] extends AnyRef

    Mapping from a BSON string to T

  38. sealed trait MacroConfiguration extends AnyRef

    Macro configuration

  39. sealed trait MacroOptions extends AnyRef

    Macros with 'Opts' suffix will take additional options in the form of type parameters that will customize behaviour of the macros during compilation.

  40. sealed trait Producer[T] extends AnyRef
  41. type StringOps = scala.collection.StringOps
    Definition Classes
    Aliases
  42. sealed trait Subtype extends AnyRef

    Binary Subtype

  43. trait TypeNaming extends (Class[_]) => String

    Naming strategy, to map each class to a discriminator value.

  44. final class ¬[A, B] extends AnyRef

    Type level evidence that type A is not type B.

    Type level evidence that type A is not type B.

    Annotations
    @SuppressWarnings()

Value Members

  1. def array(values: Producer[BSONValue]*): BSONArray

    Returns an array with given values.

    Returns an array with given values.

    import reactivemongo.api.bson._
    
    val arr = array("bar", 1L) // [ 'bar', NumberLong(1) ]
  2. def array: BSONArray

    Returns an empty array.

    Returns an empty array.

    import reactivemongo.api.bson._
    
    val arr1 = BSONString("bar") +: array // [ 'bar' ]
    val arr2 = BSONInteger(1) +: arr1 // [ 1, 'bar' ]
  3. def bsonLocalDateHandler(zone: ZoneId): BSONHandler[LocalDate]

    Returns a BSON handler for java.time.LocalDate, considering the specified time zone.

    Returns a BSON handler for java.time.LocalDate, considering the specified time zone.

    Definition Classes
    DefaultBSONHandlers
    Annotations
    @inline()
  4. implicit val bsonLocalDateHandler: BSONHandler[LocalDate]
    Definition Classes
    DefaultBSONHandlers
  5. def bsonLocalDateTimeHandler(zone: ZoneId): BSONHandler[LocalDateTime]

    Returns a BSON handler for java.time.LocalDateTime, considering the specified time zone.

    Returns a BSON handler for java.time.LocalDateTime, considering the specified time zone.

    Definition Classes
    DefaultBSONHandlers
    Annotations
    @inline()
  6. implicit val bsonLocalDateTimeHandler: BSONHandler[LocalDateTime]
    Definition Classes
    DefaultBSONHandlers
  7. implicit def bsonMapKeyWriter[K, V <: BSONValue](implicit keyWriter: KeyWriter[K]): BSONDocumentWriter[Map[K, V]]
    Definition Classes
    LowPriority3BSONHandlers
  8. implicit def bsonMapWriter[V <: BSONValue]: BSONDocumentWriter[Map[String, V]]
    Definition Classes
    LowPriority1BSONHandlers
  9. def bsonOffsetDateTimeHandler(zone: ZoneId): BSONHandler[OffsetDateTime]

    Returns a BSON handler for java.time.OffsetDateTime, considering the specified time zone.

    Returns a BSON handler for java.time.OffsetDateTime, considering the specified time zone.

    Definition Classes
    DefaultBSONHandlers
    Annotations
    @inline()
  10. implicit val bsonOffsetDateTimeHandler: BSONHandler[OffsetDateTime]
    Definition Classes
    DefaultBSONHandlers
  11. def bsonZonedDateTimeHandler(zone: ZoneId): BSONHandler[ZonedDateTime]

    Returns a BSON handler for java.time.ZonedDateTime, considering the specified time zone.

    Returns a BSON handler for java.time.ZonedDateTime, considering the specified time zone.

    Definition Classes
    DefaultBSONHandlers
    Annotations
    @inline()
  12. implicit val bsonZonedDateTimeHandler: BSONHandler[ZonedDateTime]
    Definition Classes
    DefaultBSONHandlers
  13. implicit final def collectionReader[M[_], T](implicit f: Factory[T, M[T]], reader: BSONReader[T]): BSONReader[M[T]]
    Definition Classes
    LowPriorityBSONHandlersCompat
  14. implicit def collectionWriter[T, Repr](implicit arg0: (Repr) => Iterable[T], writer: BSONWriter[T], notOption: ¬[Repr, Option[T]]): BSONWriter[Repr]
    Definition Classes
    LowPriority1BSONHandlers
    Annotations
    @silent()
  15. def document(elements: ElementProducer*): BSONDocument

    Returns a document with given elements.

    Returns a document with given elements.

    import reactivemongo.api.bson._
    
    val doc = document("foo" -> 1)
    // { 'foo': 1 }
  16. def document: BSONDocument

    Returns an empty document.

    Returns an empty document.

    import reactivemongo.api.bson._
    
    val doc = document ++ ("foo" -> 1)
    // { 'foo': 1 }
  17. def element(name: String, value: BSONValue): BSONElement
  18. def generateId: BSONObjectID

    Returns a newly generated object ID.

  19. implicit def mapKeyReader[K, V](implicit keyReader: KeyReader[K], valueReader: BSONReader[V]): BSONDocumentReader[Map[K, V]]
    Definition Classes
    LowPriority2BSONHandlers
  20. implicit def mapKeySafeWriter[K, V](implicit keyWriter: KeyWriter[K] with SafeKeyWriter[K], valueWriter: BSONWriter[V] with SafeBSONWriter[V]): BSONDocumentWriter[Map[K, V]]
    Definition Classes
    LowPriority3BSONHandlers
  21. implicit def mapKeyWriter[K, V](implicit ev: (K) => StringOps, valueWriter: BSONWriter[V]): BSONDocumentWriter[Map[K, V]]
    Definition Classes
    LowPriority4BSONHandlers
  22. implicit def mapReader[V](implicit valueReader: BSONReader[V]): BSONDocumentReader[Map[String, V]]
    Definition Classes
    LowPriority1BSONHandlers
  23. implicit def mapSafeWriter[V](implicit valueWriter: BSONWriter[V] with SafeBSONWriter[V]): BSONDocumentWriter[Map[String, V]]
    Definition Classes
    LowPriority1BSONHandlers
  24. implicit def mapWriter[V](implicit valueWriter: BSONWriter[V]): BSONDocumentWriter[Map[String, V]]
    Definition Classes
    LowPriority2BSONHandlers
  25. implicit def nameValueOrdering[T <: BSONValue]: Ordering[(String, T)]

    Key/value ordering

    Key/value ordering

    import reactivemongo.api.bson.BSONString
    
    Seq("foo" -> BSONString("1"), "bar" -> BSONString("1")).
      sorted // == [ "bar" -> .., "foo" -> .. ]
  26. object BSON

    Utility functions

  27. object BSONArray

    BSONArray utilities

    BSONArray utilities

    import reactivemongo.api.bson.{ BSONArray, BSONString }
    
    BSONArray("foo", 1) match {
      case BSONArray(BSONString(s) +: _) => s == "foo"
      case _ => false
    }
  28. implicit object BSONArrayIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONArray]
    Definition Classes
    BSONIdentityHandlers
  29. object BSONBinary

    BSONBinary utilities

    BSONBinary utilities

    import reactivemongo.api.bson.{ BSONBinary, Subtype }
    
    val bin1 = BSONBinary(
      "foo".getBytes("UTF-8"), Subtype.GenericBinarySubtype)
    
    // See Subtype.UuidSubtype
    val uuid = BSONBinary(java.util.UUID.randomUUID())
  30. implicit object BSONBinaryHandler extends BSONHandler[Array[Byte]] with SafeBSONWriter[Array[Byte]]
    Definition Classes
    DefaultBSONHandlers
  31. implicit object BSONBinaryIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONBinary]
    Definition Classes
    BSONIdentityHandlers
  32. object BSONBoolean
  33. implicit object BSONBooleanHandler extends BSONHandler[Boolean] with SafeBSONWriter[Boolean]
    Definition Classes
    DefaultBSONHandlers
  34. implicit object BSONBooleanIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONBoolean]
    Definition Classes
    BSONIdentityHandlers
  35. object BSONBooleanLike

    BSONBooleanLike utilities

  36. object BSONDateTime
  37. implicit object BSONDateTimeHandler extends BSONHandler[Instant] with SafeBSONWriter[Instant]
    Definition Classes
    DefaultBSONHandlers
  38. implicit object BSONDateTimeIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONDateTime]
    Definition Classes
    BSONIdentityHandlers
  39. object BSONDecimal
  40. implicit object BSONDecimalHandler extends BSONHandler[BigDecimal]
    Definition Classes
    DefaultBSONHandlers
  41. implicit object BSONDecimalIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONDecimal]
    Definition Classes
    BSONIdentityHandlers
  42. object BSONDocument

    BSONDocument factories & utilities.

  43. object BSONDocumentHandler

    Handler factory

  44. implicit object BSONDocumentIdentity extends BSONDocumentReader[BSONDocument] with BSONDocumentWriter[BSONDocument]
    Definition Classes
    BSONIdentityHandlers
  45. object BSONDocumentReader
  46. object BSONDocumentWriter
  47. object BSONDouble

    BSONDouble utilities

    BSONDouble utilities

    import reactivemongo.api.bson.BSONDouble
    
    BSONDouble(1.23D) match {
      case BSONDouble(v) => assert(v == 1.23D)
      case _ => ???
    }
  48. implicit object BSONDoubleHandler extends BSONHandler[Double] with SafeBSONWriter[Double]
    Definition Classes
    DefaultBSONHandlers
  49. implicit object BSONDoubleIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONDouble]
    Definition Classes
    BSONIdentityHandlers
  50. object BSONElement extends BSONElementLowPriority

    BSONElement factories and utilities.

  51. implicit object BSONFloatHandler extends BSONHandler[Float] with SafeBSONWriter[Float]
    Definition Classes
    DefaultBSONHandlers
  52. object BSONHandler
  53. object BSONInteger
  54. implicit object BSONIntegerHandler extends BSONHandler[Int] with SafeBSONWriter[Int]
    Definition Classes
    DefaultBSONHandlers
  55. implicit object BSONIntegerIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONInteger]
    Definition Classes
    BSONIdentityHandlers
  56. object BSONJavaScript
  57. implicit object BSONJavaScriptIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONJavaScript]
    Definition Classes
    BSONIdentityHandlers
  58. object BSONJavaScriptWS
  59. implicit object BSONJavaScriptWSIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONJavaScriptWS]
    Definition Classes
    BSONIdentityHandlers
  60. object BSONLong
  61. implicit object BSONLongHandler extends BSONHandler[Long] with SafeBSONWriter[Long]
    Definition Classes
    DefaultBSONHandlers
  62. implicit object BSONLongIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONLong]
    Definition Classes
    BSONIdentityHandlers
  63. object BSONMaxKey extends BSONMaxKey
  64. implicit object BSONMaxKeyIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONMaxKey]
    Definition Classes
    BSONIdentityHandlers
  65. object BSONMinKey extends BSONMinKey
  66. implicit object BSONMinKeyIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONMinKey]
    Definition Classes
    BSONIdentityHandlers
  67. object BSONNull extends BSONNull
  68. implicit object BSONNullIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONNull]
    Definition Classes
    BSONIdentityHandlers
  69. object BSONNumberLike

    BSONNumberLike utilities

  70. object BSONObjectID

    BSONObjectID utilities

  71. implicit object BSONObjectIDIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONObjectID]
    Definition Classes
    BSONIdentityHandlers
  72. object BSONReader

    BSONReader factories

  73. object BSONRegex
  74. implicit object BSONRegexIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONRegex]
    Definition Classes
    BSONIdentityHandlers
  75. object BSONString

    BSONString utilities

    BSONString utilities

    import reactivemongo.api.bson.BSONString
    
    BSONString("foo") match {
      case BSONString(v) => v == "foo"
      case _ => false
    }
  76. implicit object BSONStringHandler extends BSONHandler[String] with SafeBSONWriter[String]
    Definition Classes
    DefaultBSONHandlers
  77. implicit object BSONStringIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONString]
    Definition Classes
    BSONIdentityHandlers
  78. object BSONSymbol
  79. implicit object BSONSymbolIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONSymbol]
    Definition Classes
    BSONIdentityHandlers
  80. object BSONTimestamp

    Timestamp companion

  81. implicit object BSONTimestampIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONTimestamp]
    Definition Classes
    BSONIdentityHandlers
  82. implicit object BSONURIHandler extends BSONHandler[URI] with SafeBSONWriter[URI]
    Definition Classes
    DefaultBSONHandlers
  83. implicit object BSONURLHandler extends BSONHandler[URL] with SafeBSONWriter[URL]
    Definition Classes
    DefaultBSONHandlers
  84. object BSONUndefined extends BSONUndefined

    Single value for BSONUndefined type

  85. implicit object BSONUndefinedIdentity extends bson.DefaultBSONHandlers.IdentityBSONHandler[BSONUndefined]
    Definition Classes
    BSONIdentityHandlers
  86. object BSONValue extends BSONValueLowPriority1

    BSONValue factories and utilities

  87. implicit object BSONValueIdentity extends BSONReader[BSONValue] with BSONWriter[BSONValue]
    Definition Classes
    BSONIdentityLowPriorityHandlers
  88. object BSONWriter
  89. object ElementProducer extends ElementProducerLowPriority
  90. object FieldNaming

    Naming companion

  91. object KeyReader
  92. object KeyWriter extends LowPriorityKeyWriter
  93. object MacroConfiguration
  94. object MacroOptions
  95. object Macros

    Macros for generating BSONReader and BSONWriter at compile time.

    Macros for generating BSONReader and BSONWriter at compile time.

    import reactivemongo.api.bson.Macros
    
    case class Person(name: String, surname: String)
    
    implicit val personHandler = Macros.handler[Person]
    See also

    MacroOptions for specific options

    MacroConfiguration for extended configuration

  96. object Subtype
  97. object TypeNaming
  98. object ¬
    Annotations
    @SuppressWarnings()

Inherited from Utils

Inherited from Aliases

Inherited from DefaultBSONHandlers

Inherited from BSONIdentityHandlers

Inherited from BSONIdentityLowPriorityHandlers

Inherited from LowPriority1BSONHandlers

Inherited from LowPriority2BSONHandlers

Inherited from LowPriority3BSONHandlers

Inherited from LowPriority4BSONHandlers

Inherited from LowPriorityBSONHandlersCompat

Inherited from AnyRef

Inherited from Any

Ungrouped