BSONArray

object BSONArray

BSONArray utilities

import reactivemongo.api.bson.{ BSONArray, BSONString }

BSONArray("foo", 1) match {
 case BSONArray(BSONString(s) +: _) => s == "foo"
 case _ => false
}
Companion:
class
class Object
trait Matchable
class Any

Value members

Concrete methods

Creates a new BSONArray containing all the values. In case of conversion error for a field value, the field is ignored.

Creates a new BSONArray containing all the values. In case of conversion error for a field value, the field is ignored.

reactivemongo.api.bson.BSONArray("foo", 1L)
// [ 'foo', NumberLong(1) ]

Creates a new BSONArray containing all the values in the given sequence.

Creates a new BSONArray containing all the values in the given sequence.

import reactivemongo.api.bson.{ BSONArray, BSONLong, BSONString }

BSONArray(Seq(BSONString("foo"), BSONLong(1L)))
// [ 'foo', NumberLong(1) ]

Creates a new BSONArray containing all the values in the given Iterable.

Creates a new BSONArray containing all the values in the given Iterable.

import reactivemongo.api.bson.{ BSONArray, BSONLong, BSONString }

BSONArray(List(BSONString("foo"), BSONLong(1L)))
// [ 'foo', NumberLong(1) ]
def pretty(array: BSONArray): String

Returns a String representing the given BSONArray.

Returns a String representing the given BSONArray.

import reactivemongo.api.bson.BSONArray

BSONArray pretty BSONArray("foo", 1L)
// "[ 'foo', NumberLong(1) ]"

Creates a new BSONArray containing all the values. Fails if any error occurs while converting the values.

Creates a new BSONArray containing all the values. Fails if any error occurs while converting the values.

reactivemongo.api.bson.BSONArray.safe("foo", 1L)
// Success: [ 'foo', NumberLong(1) ]

Extracts the values sequence if that's a BSONArray.

Extracts the values sequence if that's a BSONArray.

import reactivemongo.api.bson.{ BSONArray, BSONValue }

def foo(input: BSONValue): Unit = input match {
 case BSONArray(vs) => pretty(vs)
 case _ => println("Not a BSON array")
}

def bar(arr: BSONArray): Unit = arr match {
 // with splat pattern
 case BSONArray(Seq(requiredFirst, other @ _*)) =>
   println(s"first = \$requiredFirst")
   pretty(other)

 case _ =>
   println("BSON array doesn't match")
}

def pretty(values: Seq[BSONValue]): Unit =
 println(values.map(BSONValue.pretty).mkString(", "))

Concrete fields

An empty BSONArray.

An empty BSONArray.

import reactivemongo.api.bson.{ BSONArray, BSONString }

val initial = BSONArray.empty // []

initial ++ BSONString("lorem") // [ 'lorem' ]