diff --git a/driver-core/src/main/com/mongodb/client/model/Updates.java b/driver-core/src/main/com/mongodb/client/model/Updates.java index 82595cc79c8..64b403cb6d9 100644 --- a/driver-core/src/main/com/mongodb/client/model/Updates.java +++ b/driver-core/src/main/com/mongodb/client/model/Updates.java @@ -66,6 +66,17 @@ public static Bson combine(final List updates) { return new CompositeUpdate(updates); } + /** + * Creates an update that sets the values for the document. + * + * @param value the value + * @return the update + * @mongodb.driver.manual reference/operator/update/set/ $set + */ + public static Bson set(final Bson value) { + return new SimpleBsonKeyValue("$set", value); + } + /** * Creates an update that sets the value of the field with the given name to the given value. * diff --git a/driver-core/src/test/unit/com/mongodb/client/model/UpdatesSpecification.groovy b/driver-core/src/test/unit/com/mongodb/client/model/UpdatesSpecification.groovy index 4f5e88cdf7a..7feb2ff7ea8 100644 --- a/driver-core/src/test/unit/com/mongodb/client/model/UpdatesSpecification.groovy +++ b/driver-core/src/test/unit/com/mongodb/client/model/UpdatesSpecification.groovy @@ -174,6 +174,10 @@ class UpdatesSpecification extends Specification { }''') } + def 'should set document'() { + toBson(set(parse('{ a : 1, b: "two"}'))) == parse('{$set : {a: 1, b: "two"} }') + } + def 'should create string representation for simple updates'() { expect: set('x', 1).toString() == 'Update{fieldName=\'x\', operator=\'$set\', value=1}'