Packages

sealed abstract class BSONDocument extends BSONValue with ElementProducer with SafeProducer[BSONElement] with BSONDocumentLowPriority with BSONDocumentExperimental

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.

Self Type
BSONDocument
Linear Supertypes
BSONDocumentExperimental, BSONDocumentLowPriority, SafeProducer[BSONElement], ElementProducer, Producer[BSONElement], BSONValue, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. BSONDocument
  2. BSONDocumentExperimental
  3. BSONDocumentLowPriority
  4. SafeProducer
  5. ElementProducer
  6. Producer
  7. BSONValue
  8. AnyRef
  9. Any
Implicitly
  1. by valueProducer
  2. by identityValueProducer
  3. by any2stringadd
  4. by StringFormat
  5. by Ensuring
  6. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def elements: Seq[BSONElement]

    The document fields as a sequence of BSONElements.

  2. abstract def headOption: Option[BSONElement]

    The first/mandatory element, if any.

    The first/mandatory element, if any.

    import reactivemongo.api.bson.BSONDocument
    
    BSONDocument("foo" -> 1).
      headOption // Some(BSONInteger(1))
  3. abstract def isEmpty: Boolean

    Indicates whether this document is empty

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from BSONDocument to any2stringadd[BSONDocument] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ++(seq: BSONElement*): BSONDocument

    Creates a new BSONDocument containing all the elements of this one and the specified element sequence.

    Creates a new BSONDocument containing all the elements of this one and the specified element sequence.

    import reactivemongo.api.bson.{
      BSONDocument, BSONElement, BSONString
    }
    
    val doc = BSONDocument("foo" -> 1)
    
    doc ++ BSONElement("bar", BSONString("lorem"))
    // { 'foo': 1, 'bar': 'lorem' }
  5. def ++(doc: BSONDocument): BSONDocument

    Returns the BSONDocument containing all the elements of this one and the elements of the given document.

    Returns the BSONDocument containing all the elements of this one and the elements of the given document.

    import reactivemongo.api.bson.BSONDocument
    
    val doc1 = BSONDocument("foo" -> 1)
    val doc2 = BSONDocument("bar" -> "lorem")
    
    doc1 ++ doc2 // { 'foo': 1, 'bar': 'lorem' }
  6. def ++(producers: ElementProducer*): BSONDocument

    Creates a new BSONDocument containing all the elements of this one and the specified element producers.

    Creates a new BSONDocument containing all the elements of this one and the specified element producers.

    import reactivemongo.api.bson.BSONDocument
    
    val doc = BSONDocument("foo" -> 1)
    
    doc ++ ("bar" -> "lorem") // { 'foo': 1, 'bar': 'lorem' }
    Definition Classes
    BSONDocumentLowPriority
  7. def --(keys: String*): BSONDocument

    Returns a set without the values corresponding to the specified keys.

    Returns a set without the values corresponding to the specified keys.

    import reactivemongo.api.bson.BSONDocument
    
    val doc = BSONDocument("foo" -> 1, "bar" -> "v")
    
    doc -- "bar" // { 'foo': 1 }
  8. def ->[B](y: B): (BSONDocument, B)
    Implicit
    This member is added by an implicit conversion from BSONDocument to ArrowAssoc[BSONDocument] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  9. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  10. def array(name: String): Option[Seq[BSONValue]]

    EXPERIMENTAL: Returns the named element from the current document, if the element is an array field.

    EXPERIMENTAL: Returns the named element from the current document, if the element is an array field.

    Definition Classes
    BSONDocumentExperimental
  11. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  12. final def asOpt[T](implicit reader: BSONReader[T]): Option[T]

    Optionally parses this value as a T one.

    Optionally parses this value as a T one.

    returns

    Some successfully parsed value, or None if fails

    import reactivemongo.api.bson.BSONValue
    
    def foo(v: BSONValue): Option[String] = v.asOpt[String]
    Definition Classes
    BSONValue
    Annotations
    @inline()
  13. def asStrict: Strict

    EXPERIMENTAL: Returns a strict representation (with only the last value kept per each field name).

    EXPERIMENTAL: Returns a strict representation (with only the last value kept per each field name).

    reactivemongo.api.bson.BSONDocument(
      "foo" -> 1, "bar" -> 2, "foo" -> 3).asStrict
    // { 'foo': 3, 'bar': 2 }
    Definition Classes
    BSONDocumentExperimental
  14. final def asTry[T](implicit reader: BSONReader[T]): Try[T]

    Tries to parse this value as a T one.

    Tries to parse this value as a T one.

    import scala.util.Try
    import reactivemongo.api.bson.BSONValue
    
    def foo(v: BSONValue): Try[String] = v.asTry[String]
    Definition Classes
    BSONValue
  15. def binary(name: String): Option[Array[Byte]]

    EXPERIMENTAL: Returns the named element from the current document, if the element is a binary field.

    EXPERIMENTAL: Returns the named element from the current document, if the element is a binary field.

    Definition Classes
    BSONDocumentExperimental
  16. def booleanLike(name: String): Option[Boolean]

    EXPERIMENTAL: Returns the named element from the current document, if the element is a boolean-like field (numeric or boolean).

    EXPERIMENTAL: Returns the named element from the current document, if the element is a boolean-like field (numeric or boolean).

    Definition Classes
    BSONDocumentExperimental
  17. val byteCode: Byte

    The code indicating the BSON type for this value as Byte

    The code indicating the BSON type for this value as Byte

    Definition Classes
    BSONDocumentBSONValue
  18. def child(name: String): Option[BSONDocument]

    EXPERIMENTAL: Returns the named element from the current document, if the element is a nested document.

    EXPERIMENTAL: Returns the named element from the current document, if the element is a nested document.

    Definition Classes
    BSONDocumentExperimental
  19. def children(name: String): List[BSONDocument]

    EXPERIMENTAL: Returns the named element from the current document, if the element is a list of nested documents.

    EXPERIMENTAL: Returns the named element from the current document, if the element is a list of nested documents.

    Definition Classes
    BSONDocumentExperimental
  20. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  21. val code: Int

    The code indicating the BSON type for this value

    The code indicating the BSON type for this value

    Definition Classes
    BSONDocumentBSONValue
  22. def contains(key: String): Boolean

    Checks whether the given key is found in this element set.

    Checks whether the given key is found in this element set.

    import reactivemongo.api.bson.BSONDocument
    
    val doc = BSONDocument("foo" -> 1)
    
    doc.contains("foo") // true
    doc.contains("bar") // false
    key

    the key to be found in the document

    returns

    true if the key is found

  23. def double(name: String): Option[Double]

    EXPERIMENTAL: Returns the named element from the current document, if the element is a double field.

    EXPERIMENTAL: Returns the named element from the current document, if the element is a double field.

    Definition Classes
    BSONDocumentExperimental
  24. def ensuring(cond: (BSONDocument) ⇒ Boolean, msg: ⇒ Any): BSONDocument
    Implicit
    This member is added by an implicit conversion from BSONDocument to Ensuring[BSONDocument] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  25. def ensuring(cond: (BSONDocument) ⇒ Boolean): BSONDocument
    Implicit
    This member is added by an implicit conversion from BSONDocument to Ensuring[BSONDocument] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  26. def ensuring(cond: Boolean, msg: ⇒ Any): BSONDocument
    Implicit
    This member is added by an implicit conversion from BSONDocument to Ensuring[BSONDocument] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  27. def ensuring(cond: Boolean): BSONDocument
    Implicit
    This member is added by an implicit conversion from BSONDocument to Ensuring[BSONDocument] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  28. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  29. def equals(that: Any): Boolean
    Definition Classes
    BSONDocument → AnyRef → Any
  30. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  31. final def get(key: String): Option[BSONValue]

    Returns the BSONValue associated with the given key.

    Returns the BSONValue associated with the given key. If the key cannot be found, returns None.

    import reactivemongo.api.bson.BSONDocument
    
    val doc = BSONDocument("foo" -> 1)
    
    doc.get("foo") // Some(BSONInteger(1))
    doc.contains("bar") // None
    key

    the key to be found in the document

  32. final def getAsOpt[T](key: String)(implicit reader: BSONReader[T]): Option[T]

    Returns the BSONValue associated with the given key, and converts it with the given implicit BSONReader.

    Returns the BSONValue associated with the given key, and converts it with the given implicit BSONReader.

    If there is no matching value (or value is a BSONNull), or the value could not be deserialized, or converted, returns a None.

    import reactivemongo.api.bson.{ BSONDocument, BSONNull }
    
    val doc = BSONDocument("foo" -> 1, "bar" -> BSONNull)
    
    doc.getAsOpt[Int]("foo") // Some(1)
    doc.getAsOpt[String]("foo") // None, as not a string
    doc.getAsOpt[Int]("lorem") // None, no 'lorem' key
    doc.getAsOpt[Int]("bar") // None, as `BSONNull`
    key

    the key to be found in the document

    Note

    When implementing a custom reader, getAsTry must be preferred.

  33. final def getAsTry[T](key: String)(implicit reader: BSONReader[T]): Try[T]

    Gets the BSONValue associated with the given key, and converts it with the given implicit BSONReader.

    Gets the BSONValue associated with the given key, and converts it with the given implicit BSONReader.

    If there is no matching value, or the value could not be deserialized, or converted, returns a Failure.

    The Failure may hold a exceptions.BSONValueNotFoundException, if the key could not be found.

    import reactivemongo.api.bson.{ BSONDocument, BSONNull }
    
    val doc = BSONDocument("foo" -> 1, "bar" -> BSONNull)
    
    doc.getAsTry[Int]("foo") // Success(1)
    doc.getAsTry[String]("foo") // Failure(..), as not a string
    
    doc.getAsTry[Int]("lorem")
    // Failure(BSONValueNotFoundException), no 'lorem' key
    
    doc.getAsTry[Int]("bar")
    // Failure(BSONValueNotFoundException), as `BSONNull`
    key

    the key to be found in the document

  34. final def getAsUnflattenedTry[T](key: String)(implicit reader: BSONReader[T]): Try[Option[T]]

    Gets the BSONValue at the given key, and converts it with the given implicit BSONReader.

    Gets the BSONValue at the given key, and converts it with the given implicit BSONReader.

    If there is no matching value, Success(None) is returned. If there is a value, it must be valid or a Failure is returned.

    import reactivemongo.api.bson.{ BSONDocument, BSONNull }
    
    val doc = BSONDocument("foo" -> 1, "bar" -> BSONNull)
    
    doc.getAsUnflattenedTry[Int]("foo") // Success(Some(1))
    
    doc.getAsUnflattenedTry[String]("foo") // Failure(..), as not a string
    
    doc.getAsUnflattenedTry[Int]("lorem")
    // Success(None), no 'lorem' key
    
    doc.getAsUnflattenedTry[Int]("bar")
    // Success(None), as `BSONNull`
    key

    the key to be found in the document

  35. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  36. final def getOrElse[T](key: String, default: ⇒ T)(implicit reader: BSONReader[T]): T

    Returns the BSONValue associated with the given key, and converts it with the given implicit BSONReader.

    Returns the BSONValue associated with the given key, and converts it with the given implicit BSONReader.

    If there is no matching value (or value is a BSONNull), or the value could not be deserialized, or converted, returns the default value.

    import reactivemongo.api.bson.{ BSONDocument, BSONNull }
    
    val doc = BSONDocument("foo" -> 1, "bar" -> BSONNull)
    
    doc.getOrElse[Int]("foo", -1) // 1
    doc.getOrElse[String]("foo", "default") // 'default', as not a string
    doc.getOrElse[Int]("lorem", -1) // -1, no 'lorem' key
    doc.getOrElse[Int]("bar", -1) // -1, as `BSONNull`
    key

    the key to be found in the document

    Note

    When implementing a custom reader, getAsTry must be preferred.

  37. final def getRawAsTry[T](key: String)(implicit reader: BSONReader[T]): Try[T]

    Gets the BSONValue associated with the given key, and converts it with the given implicit BSONReader.

    Gets the BSONValue associated with the given key, and converts it with the given implicit BSONReader.

    If there is no matching value, or the value could not be deserialized, or converted, returns a Failure.

    The Failure may hold a exceptions.BSONValueNotFoundException, if the key could not be found.

    Contrary to getAsTry (which must generally be preferred), if the value is BSONNull it passed to the given reader (not skipped).

    key

    the key to be found in the document

  38. def hashCode(): Int
    Definition Classes
    BSONDocument → AnyRef → Any
  39. def int(name: String): Option[Int]

    EXPERIMENTAL: Returns the named element from the current document, if the element is a integer field.

    EXPERIMENTAL: Returns the named element from the current document, if the element is a integer field.

    Definition Classes
    BSONDocumentExperimental
  40. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  41. def long(name: String): Option[Long]

    EXPERIMENTAL: Returns the named element from the current document, if the element is a long field.

    EXPERIMENTAL: Returns the named element from the current document, if the element is a long field.

    Definition Classes
    BSONDocumentExperimental
  42. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  43. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  44. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  45. def size: Int

    The number of fields

    The number of fields

    Annotations
    @inline()
  46. def string(name: String): Option[String]

    EXPERIMENTAL: Returns the named element from the current document, if the element is a string field.

    EXPERIMENTAL: Returns the named element from the current document, if the element is a string field.

    Definition Classes
    BSONDocumentExperimental
  47. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  48. final def toMap: Map[String, BSONValue]

    Returns the Map representation for this document.

    Returns the Map representation for this document.

    import reactivemongo.api.bson.BSONDocument
    
    BSONDocument("foo" -> 1).toMap
    // => Map("foo" -> BSONInteger(1))
    Annotations
    @inline()
  49. def toString(): String
    Definition Classes
    BSONDocument → AnyRef → Any
  50. def uuid(name: String): Option[UUID]

    EXPERIMENTAL: Returns the named element from the current document, if the element is a binary/uuid field.

    EXPERIMENTAL: Returns the named element from the current document, if the element is a binary/uuid field.

    Definition Classes
    BSONDocumentExperimental
  51. final def values: Iterable[BSONValue]

    Returns the values of the document fields.

    Returns the values of the document fields.

    import reactivemongo.api.bson.BSONDocument
    
    BSONDocument("foo" -> 1).
      values // Seq(BSONInteger(1))
  52. final def values[T](name: String)(implicit r: BSONReader[T]): Option[Seq[T]]
    Definition Classes
    BSONDocumentExperimental
  53. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  54. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  55. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  56. def [B](y: B): (BSONDocument, B)
    Implicit
    This member is added by an implicit conversion from BSONDocument to ArrowAssoc[BSONDocument] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Deprecated Value Members

  1. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from BSONDocument to StringFormat[BSONDocument] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @deprecated @inline()
    Deprecated

    (Since version 2.12.16) Use formatString.format(value) instead of value.formatted(formatString), or use the f"" string interpolator. In Java 15 and later, formatted resolves to the new method in String which has reversed parameters.

Inherited from BSONDocumentExperimental

Inherited from BSONDocumentLowPriority

Inherited from SafeProducer[BSONElement]

Inherited from ElementProducer

Inherited from Producer[BSONElement]

Inherited from BSONValue

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion valueProducer from BSONDocument to Producer[BSONValue]

Inherited by implicit conversion identityValueProducer from BSONDocument to Producer[BSONValue]

Inherited by implicit conversion any2stringadd from BSONDocument to any2stringadd[BSONDocument]

Inherited by implicit conversion StringFormat from BSONDocument to StringFormat[BSONDocument]

Inherited by implicit conversion Ensuring from BSONDocument to Ensuring[BSONDocument]

Inherited by implicit conversion ArrowAssoc from BSONDocument to ArrowAssoc[BSONDocument]

Ungrouped