Skip to content

Latest commit

 

History

History
105 lines (93 loc) · 1.83 KB

bsondsl.md

File metadata and controls

105 lines (93 loc) · 1.83 KB

BsonDsl

There are 2 different DSLs which are reactivemongo.bson.BsonDsl and reactivemongo.extensions.dsl.functional.BsonDsl. functional.BsonDsl provides infix syntax.

$doc

// Input
$doc("name" -> "foo", "surname" -> "bar", "age" -> 32)
// Output
BSONDocument("name" -> "foo", "surname" -> "bar", "age" -> 32)

// Input
$docx("age", $gtx(50), $ltx(60))
// Infix syntax
"age" $gt 50 $lt 60
// Output
BSONDocument("age" -> BSONDocument("$gt" -> 50, "$lt" -> 60))

$ne

// Input
$ne("name" -> "foo")
// Infix syntax
"name" $ne "foo"
// Output
BSONDocument("name" -> BSONDocument("$ne" -> "foo"))

$gt

// Input
$gt("age" -> 16)
// Infix syntax
"age" $gt 16
// Output
BSONDocument("age" -> BSONDocument("$gt" -> 16))

$gte

// Input
$gte("age" -> 16)
// Infix syntax
"age" $gte 16
// Output
BSONDocument("age" -> BSONDocument("$gte" -> 16))

$in

// Input
$in("age", Seq(1, 2, 3))
// Infix syntax
"age" $in Seq(1, 2, 3)
// Output
BSONDocument("age" -> BSONDocument("$in" -> BSONArray(1, 2, 3)))

$lt

// Input
$lt("age" -> 16)
// Infix syntax
"age" $lt 16
// Output
BSONDocument("age" -> BSONDocument("$lt" -> 16))

$lte

// Input
$lte("age" -> 16)
// Infix syntax
"age" $lte 16
// Output
BSONDocument("age" -> BSONDocument("$lte" -> 16))

$nin

// Input
$nin("age", Seq(1, 2, 3))
// Infix syntax
"age" $nin Seq(1, 2, 3)
// Output
BSONDocument("age" -> BSONDocument("$nin" -> BSONArray(1, 2, 3)))

$set

// Input
$set("name" -> "foo", "surname" -> "bar", "age" -> 32)
// Output
BSONDocument("$set" -> BSONDocument("name" -> "foo", "surname" -> "bar", "age" -> 32))

$unset

// Input
$unset("name", "surname", "age")
// Output
BSONDocument("$unset" -> BSONDocument("name" -> "", "surname" -> "", "age" -> ""))