use of com.mongodb.client.model.DeleteOneModel in project mongo-java-driver by mongodb.
the class UnifiedCrudHelper method toWriteModel.
private WriteModel<BsonDocument> toWriteModel(final BsonDocument document) {
String requestType = document.getFirstKey();
BsonDocument arguments = document.getDocument(requestType);
switch(requestType) {
case "insertOne":
return new InsertOneModel<>(arguments.getDocument("document"));
case "updateOne":
return arguments.isArray("update") ? new UpdateOneModel<>(arguments.getDocument("filter"), arguments.getArray("update").stream().map(BsonValue::asDocument).collect(toList()), getUpdateOptions(arguments)) : new UpdateOneModel<>(arguments.getDocument("filter"), arguments.getDocument("update"), getUpdateOptions(arguments));
case "updateMany":
return arguments.isArray("update") ? new UpdateManyModel<>(arguments.getDocument("filter"), arguments.getArray("update").stream().map(BsonValue::asDocument).collect(toList()), getUpdateOptions(arguments)) : new UpdateManyModel<>(arguments.getDocument("filter"), arguments.getDocument("update"), getUpdateOptions(arguments));
case "deleteOne":
return new DeleteOneModel<>(arguments.getDocument("filter"), getDeleteOptions(arguments));
case "deleteMany":
return new DeleteManyModel<>(arguments.getDocument("filter"), getDeleteOptions(arguments));
case "replaceOne":
return new ReplaceOneModel<>(arguments.getDocument("filter"), arguments.getDocument("replacement"), getReplaceOptions(arguments));
default:
throw new UnsupportedOperationException("Unsupported write model type: " + requestType);
}
}
Aggregations