
io.kestra.plugin.mongodb.AbstractTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plugin-mongodb Show documentation
Show all versions of plugin-mongodb Show documentation
Access and manipulate MongoDB data within Kestra workflows.
package io.kestra.plugin.mongodb;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.tasks.Task;
import io.kestra.core.runners.RunContext;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.bson.conversions.Bson;
import jakarta.validation.constraints.NotNull;
@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
public abstract class AbstractTask extends Task {
@Schema(
title = "MongoDB connection properties."
)
@NotNull
protected MongoDbConnection connection;
@Schema(
title = "MongoDB database."
)
@PluginProperty(dynamic = true)
@NotNull
protected String database;
@Schema(
title = "MongoDB collection."
)
@PluginProperty(dynamic = true)
@NotNull
protected String collection;
protected MongoCollection collection(RunContext runContext, MongoClient client) throws IllegalVariableEvaluationException {
return this.collection(runContext, client, Bson.class);
}
protected MongoCollection collection(RunContext runContext, MongoClient client, Class cls) throws IllegalVariableEvaluationException {
MongoDatabase database = client.getDatabase(runContext.render(this.database));
return database.getCollection(
runContext.render(this.collection),
cls
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy