BSONStrictDocument
'''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)
Value members
Concrete methods
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 }
- Definition Classes
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 }
- Definition Classes
Inherited methods
'''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.
- Inherited from:
- BSONDocumentExperimental
Optionally parses this value as a T
one.
Optionally parses this value as a T
one.
- Returns:
Some
successfully parsed value, orNone
if failsimport reactivemongo.api.bson.BSONValue def foo(v: BSONValue): Option[String] = v.asOpt[String]
- Inherited from:
- BSONValue
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]
- Inherited from:
- BSONValue
'''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.
- Inherited from:
- BSONDocumentExperimental
'''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).
- Inherited from:
- BSONDocumentExperimental
'''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.
- Inherited from:
- BSONDocumentExperimental
'''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.
- Inherited from:
- BSONDocumentExperimental
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
- Value parameters:
- key
the key to be found in the document
- Returns:
true if the key is found
- Inherited from:
- BSONDocument
'''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.
- Inherited from:
- BSONDocumentExperimental
The document fields as a sequence of BSONElements.
The document fields as a sequence of BSONElements.
- Inherited from:
- BSONDocument
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
- Value parameters:
- key
the key to be found in the document
- Inherited from:
- BSONDocument
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`
- Value parameters:
- key
the key to be found in the document
- Note:
When implementing a custom reader, getAsTry must be preferred.
- Inherited from:
- BSONDocument
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`
- Value parameters:
- key
the key to be found in the document
- Inherited from:
- BSONDocument
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`
- Value parameters:
- key
the key to be found in the document
- Inherited from:
- BSONDocument
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`
- Value parameters:
- key
the key to be found in the document
- Note:
When implementing a custom reader, getAsTry must be preferred.
- 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))
- Inherited from:
- BSONDocument
'''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.
- Inherited from:
- BSONDocumentExperimental
Indicates whether this document is empty
Indicates whether this document is empty
- Inherited from:
- BSONDocument
'''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.
- Inherited from:
- BSONDocumentExperimental
'''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.
- Inherited from:
- BSONDocumentExperimental
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))
- Inherited from:
- BSONDocument
'''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.
- Inherited from:
- BSONDocumentExperimental
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))
- Inherited from:
- BSONDocument