UpdateBuilderSpec

UpdateBuilderSpec

Update operation DSL

Update operations allows atomic modification of documents within mongo collection. Following operations on documents are supported: 
 Replacing the document with new one : update(document) ({ "k" : 1 , "_id" : { "$oid" : "526536da8b5eefd71a4a2a28"}},{ "k" : 1 , "_id" : { "$oid" : "526536da8b5eefd71a4a2a28"}},{ "k" : 1 , "_id" : { "$oid" : "526536da8b5eefd71a4a2a28"}})
 Updating single key with new value : update("key" := 1) ({ "$set" : { "key" : 1}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 1 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Updating single key with new value : update("key" set 1) ({ "$set" : { "key" : 1}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 1 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Updating single key with new value : update("key" := 1, "key2" := "string") ({ "$set" : { "key" : 1 , "key2" : "string"}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 1 , "key2" : "string" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Incrementing value of given key by one : update("key" += 1) ({ "$inc" : { "key" : 1}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 11 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Incrementing value of given key by one : update("key" inc 1) ({ "$inc" : { "key" : 1}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 11 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Different update types may be mixed together : update("key" += 1, "key2" := "string", "key3" += 3, "key4" := 3) ({ "$inc" : { "key" : 1 , "key3" : 3} , "$set" : { "key2" : "string" , "key4" : 3}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 11 , "key2" : "string" , "key3" : 4 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Removing given key : update("key" -, "key2" remove) ({ "$unset" : { "key" : "" , "key2" : ""}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Renaming given key : update("key" ~> "keyR") ({ "$rename" : { "key" : "keyR"}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5 , "keyR" : 10})
 Renaming given key : update("key" renameTo "keyR") ({ "$rename" : { "key" : "keyR"}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5 , "keyR" : 10})
 Update key only when upserting : update("key" setOnInsert 1) ({ "$setOnInsert" : { "key" : 1}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Adds values to given key : update("key5" ++= Seq(1, 2, 3)) ({ "$push" : { "key5" : { "$each" : [ 1 , 2 , 3]}}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3 , 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Adds values to given key : update("key5" push Seq(1, 2, 3)) ({ "$push" : { "key5" : { "$each" : [ 1 , 2 , 3]}}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3 , 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Adds values to given key as set : update("key5" addToSet Set(2, 3, 4)) ({ "$addToSet" : { "key5" : { "$each" : [ 2 , 3 , 4]}}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3 , 4] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Adds values and sorts them : update(("key6" ++= Set[DBObject](BSONObject("n1" -> 1, "n2" -> 1))).sort("n2" Ascending).slice(5)) ({ "$push" : { "key6" : { "$each" : [ { "n1" : 1 , "n2" : 1}] , "$sort" : { "n2" : 1} , "$slice" : -5}}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 1} , { "n1" : 3 , "n2" : 2} , { "n1" : 1 , "n2" : 4}] , "key7" : 5})
 Adds values and limits array size : update(("key5" ++= Set(1, 2, 3)).slice(4)) ({ "$push" : { "key5" : { "$each" : [ 1 , 2 , 3] , "$slice" : -4}}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 3 , 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Removes all specified values from given key : update("key5" --= Seq(1, 2)) ({ "$pullAll" : { "key5" : [ 1 , 2]}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Removes all values matching query from given key : update(pull("key5" >= 3)) ({ "$pull" : { "key5" : { "$gte" : 3}}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Performs bitwise and : update("key" & 7) ({ "$bit" : { "key" : { "and" : 7}}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 2 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Performs bitwise or : update("key" | 7) ({ "$bit" : { "key" : { "or" : 7}}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 15 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Pops last item in array : update("key5" popLast) ({ "$pop" : { "key5" : 1}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Pops first item in array : update("key5" popFirst) ({ "$pop" : { "key5" : -1}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5})
 Set field if updating Option wih Some value : update("key7" := Some(12)) ({ "$set" : { "key7" : 12}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 12})
 Unset field if updating Option wih None value : update("key7" := None) ({ "$unset" : { "key7" : ""}},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}] , "key7" : 5},{ "key" : 10 , "key2" : "val1" , "key3" : 1 , "key4" : 3 , "key5" : [ 1 , 2 , 3] , "key6" : [ { "n1" : 1 , "n2" : 4} , { "n1" : 3 , "n2" : 2}]})

Total for specification UpdateBuilderSpec
Finished in4 seconds, 111 ms
Results24 examples (+2), 24 expectations (+2), 0 failure, 0 error