The document fields as a sequence of BSONElements.
The first/mandatory element, if any.
The first/mandatory element, if any.
import reactivemongo.api.bson.BSONDocument BSONDocument("foo" -> 1). headOption // Some(BSONInteger(1))
Indicates whether this document is empty
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' }
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' }
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' }
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 }
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.
Optionally parses this value as a T
one.
Optionally parses this value as a T
one.
Some
successfully parsed value, or None
if fails
import reactivemongo.api.bson.BSONValue def foo(v: BSONValue): Option[String] = v.asOpt[String]
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 }
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]
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.
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).
The code indicating the BSON type for this value as Byte
The code indicating the BSON type for this value as Byte
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.
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.
The code indicating the BSON type for this value
The code indicating the BSON type for this value
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
the key to be found in the document
true if the key is found
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.
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
the key to be found in the document
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`
the key to be found in the document
When implementing a custom reader, getAsTry must be preferred.
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`
the key to be found in the document
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`
the key to be found in the document
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`
the key to be found in the document
When implementing a custom reader, getAsTry must be preferred.
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.
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.
The number of fields
The number of fields
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.
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))
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.
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))
A
BSONDocument
structure (BSON type0x03
).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.