The BSON values
Returns a BSON array with the given values appended.
Returns a BSON array with the given values appended.
import reactivemongo.api.bson.{ BSONArray, BSONLong } val arr = BSONArray(1, "foo") arr ++ BSONLong(3L) // [ 1, 'foo', NumberLong(3) ]
Returns a BSON array with the values of the given one appended.
Returns a BSON array with the values of the given one appended.
import reactivemongo.api.bson.BSONArray val arr1 = BSONArray(1, "foo") val arr2 = BSONArray(2L, "bar") arr1 ++ arr2 // [ 1, 'foo', NumberLong(2), 'bar' ]
Returns a BSON array with the given value prepended.
Returns a BSON array with the given value prepended.
import reactivemongo.api.bson.{ BSONArray, BSONString } BSONString("foo") +: BSONArray(1L) // [ 'foo', NumberLong(1) ]
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]
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]
The code indicating the BSON type for this value as Byte
The code indicating the BSON type for this value
Returns the BSONValue at the given index
.
Returns the BSONValue at the given index
.
If there is no such index
, None
is returned.
def secondAsString( a: reactivemongo.api.bson.BSONArray): Option[String] = a.get(1).flatMap(_.asOpt[String])
the index to be found in the array (0
being the first)
Returns the BSONValue at the given index
,
and converts it with the given implicit BSONReader.
Returns the BSONValue at the given index
,
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 None
.
import reactivemongo.api.bson.BSONArray val arr = BSONArray(1, "foo") arr.getAsOpt[Int](0) // Some(1) arr.getAsOpt[Int](1) // None; "foo" not int
the index to be found in the array (0
being the first)
Gets the BSONValue at the given index
,
and converts it with the given implicit BSONReader.
Gets the BSONValue at the given index
,
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
holds a exceptions.BSONValueNotFoundException
if the index could not be found.
import reactivemongo.api.bson.BSONArray val arr = BSONArray(1, "foo") arr.getAsTry[Int](0) // Success(1) arr.getAsTry[Int](1) // Failure(BSONValueNotFoundException(..))
the index to be found in the array (0
being the first)
Gets the BSONValue at the given index
,
and converts it with the given implicit BSONReader.
Gets the BSONValue at the given index
,
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.BSONArray val arr = BSONArray(1, "foo") arr.getAsUnflattendTry[Int](0) // Success(Some(1)) arr.getAsUnflattendTry[Int](1) // Failure(BSONValueNotFoundException(..)) arr.getAsUnflattendTry[Int](2) // Success(None) // no value at 2
the index to be found in the array (0
being the first)
The first/mandatory value, if any
Indicates whether this array is empty
Indicates whether this array is empty
The number of values
The number of values
A
BSONArray
(type0x04
) is a indexed sequence of BSONValue.