BSONStrictDocument

reactivemongo.api.bson.BSONStrictDocument
sealed abstract class BSONStrictDocument extends BSONDocument

'''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)

Attributes

Graph
Supertypes
trait BSONValue
class Object
trait Matchable
class Any
Self type

Members list

Concise view

Value members

Concrete methods

final override def ++(doc: BSONDocument): BSONDocument

Concatenate the two documents, maintaining field unicity by keeping only the last value per each name.

Concatenate the two documents, maintaining field unicity by keeping only the last value per each name.

import reactivemongo.api.bson.BSONDocument

BSONDocument("foo" -> 1, "bar" -> 2) ++ BSONDocument("foo" -> 4)
// { 'foo': 4, 'bar': 2 }

Attributes

Definition Classes
final override def ++(seq: BSONElement*): Strict

Appends the given elements to the current document, or update the value for an already known field to maintain unicity.

Appends the given elements to the current document, or update the value for an already known field to maintain unicity.

reactivemongo.api.bson.BSONDocument(
 "foo" -> 1, "bar" -> 2) ++ ("foo" -> 4)
// { 'foo': 4, 'bar': 2 }

Attributes

Definition Classes
final override def --(keys: String*): Strict

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 }

Attributes

Definition Classes

Inherited methods

final override def ++(producers: ElementProducer*): Strict

Attributes

Definition Classes
BSONStrictDocumentLowPriority
Inherited from:
BSONStrictDocumentLowPriority (hidden)

'''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.

Attributes

Inherited from:
BSONDocumentExperimental (hidden)
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.

Attributes

Returns:

Some successfully parsed value, or None if fails

import reactivemongo.api.bson.BSONValue
def foo(v: BSONValue): Option[String] = v.asOpt[String]
Inherited from:
BSONValue
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]

Attributes

Inherited from:
BSONValue
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.

Attributes

Inherited from:
BSONDocumentExperimental (hidden)

'''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).

Attributes

Inherited from:
BSONDocumentExperimental (hidden)

'''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.

Attributes

Inherited from:
BSONDocumentExperimental (hidden)

'''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.

Attributes

Inherited from:
BSONDocumentExperimental (hidden)

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

Attributes

key

the key to be found in the document

Returns:

true if the key is found

Inherited from:
BSONDocument
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.

Attributes

Inherited from:
BSONDocumentExperimental (hidden)

The document fields as a sequence of BSONElements.

The document fields as a sequence of BSONElements.

Attributes

Inherited from:
BSONDocument
override def equals(that: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Attributes

that

the object to compare against this object for equality.

Returns:

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
Inherited from:
BSONDocument
final def get(key: String): Option[BSONValue]

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

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

Attributes

key

the key to be found in the document

Inherited from:
BSONDocument
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`

Attributes

key

the key to be found in the document

Note:

When implementing a custom reader, getAsTry must be preferred.

Inherited from:
BSONDocument
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`

Attributes

key

the key to be found in the document

Inherited from:
BSONDocument
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`

Attributes

key

the key to be found in the document

Inherited from:
BSONDocument
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`

Attributes

key

the key to be found in the document

Note:

When implementing a custom reader, getAsTry must be preferred.

Inherited from:
BSONDocument
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).

Attributes

key

the key to be found in the document

Inherited from:
BSONDocument
override def hashCode: Int

Calculate a hash code value for the object.

Calculate a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns:

the hash code value for this object.

Definition Classes
Inherited from:
BSONDocument

The first/mandatory element, if any.

The first/mandatory element, if any.

import reactivemongo.api.bson.BSONDocument

BSONDocument("foo" -> 1).
 headOption // Some(BSONInteger(1))

Attributes

Inherited from:
BSONDocument
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.

Attributes

Inherited from:
BSONDocumentExperimental (hidden)

Indicates whether this document is empty

Indicates whether this document is empty

Attributes

Inherited from:
BSONDocument
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.

Attributes

Inherited from:
BSONDocumentExperimental (hidden)
def size: Int

The number of fields

The number of fields

Attributes

Inherited from:
BSONDocument
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.

Attributes

Inherited from:
BSONDocumentExperimental (hidden)
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))

Attributes

Inherited from:
BSONDocument
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns:

a string representation of the object.

Definition Classes
Inherited from:
BSONDocument
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.

Attributes

Inherited from:
BSONDocumentExperimental (hidden)

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))

Attributes

Inherited from:
BSONDocument
final def values[T](name: String)(implicit r: BSONReader[T]): Option[Seq[T]]

Attributes

Inherited from:
BSONDocumentExperimental (hidden)

Concrete fields

final override val 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 }

Attributes

Inherited fields

The code indicating the BSON type for this value as Byte

The code indicating the BSON type for this value as Byte

Attributes

Inherited from:
BSONDocument
val code: Int

The code indicating the BSON type for this value

The code indicating the BSON type for this value

Attributes

Inherited from:
BSONDocument