Update operation DSL
Update operations allows atomic modification of documents within mongo collection. Following operations on documents are supported:
update(document)
({ "k" : 1 , "_id" : { "$oid" : "526536da8b5eefd71a4a2a28"}},{ "k" : 1 , "_id" : { "$oid" : "526536da8b5eefd71a4a2a28"}},{ "k" : 1 , "_id" : { "$oid" : "526536da8b5eefd71a4a2a28"}})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})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})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})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})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})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})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})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})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" 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})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})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})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})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})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})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})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})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})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})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})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})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})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 in | 4 seconds, 111 ms |
Results | 24 examples (+2), 24 expectations (+2), 0 failure, 0 error |