use of com.mongodb.client.model.ReplaceOptions in project mongo-java-driver by mongodb.
the class JsonPoweredCrudTestHelper method getReplaceOneResult.
BsonDocument getReplaceOneResult(final BsonDocument collectionOptions, final BsonDocument arguments, @Nullable final ClientSession clientSession) {
ReplaceOptions options = new ReplaceOptions();
if (arguments.containsKey("upsert")) {
options.upsert(arguments.getBoolean("upsert").getValue());
}
if (arguments.containsKey("collation")) {
options.collation(getCollation(arguments.getDocument("collation")));
}
if (arguments.containsKey("bypassDocumentValidation")) {
options.bypassDocumentValidation(arguments.getBoolean("bypassDocumentValidation").getValue());
}
if (arguments.containsKey("hint")) {
if (arguments.isDocument("hint")) {
options.hint(arguments.getDocument("hint"));
} else {
options.hintString(arguments.getString("hint").getValue());
}
}
UpdateResult updateResult;
if (clientSession == null) {
updateResult = getCollection(collectionOptions).replaceOne(arguments.getDocument("filter"), arguments.getDocument("replacement"), options);
} else {
updateResult = getCollection(collectionOptions).replaceOne(clientSession, arguments.getDocument("filter"), arguments.getDocument("replacement"), options);
}
return toResult(updateResult);
}
Aggregations