kestra-io / plugin-mongodb

https://kestra.io/plugins/plugin-mongodb/
Apache License 2.0
4 stars 4 forks source link

Bulk options are not supported #7

Open cedrelek opened 3 months ago

cedrelek commented 3 months ago

Feature description

Summary

In a bulk operations file, options are not supported. According to the mongodb reference : https://www.mongodb.com/docs/manual/reference/method/db.collection.bulkWrite/

Exemple :

In a ion file :

{"replaceOne":{
  "filter":{"entityUrn":"106852001"},
  "upsert":true,
  "replacement":{ "code":"1","type":"dog" }
}

Upsert is not supported.

How to solve Incrimined lines are : https://github.com/kestra-io/plugin-mongodb/blob/f1e08a57ad27c51c0c6a00b4f9366e385c4563de/src/main/java/io/kestra/plugin/mongodb/Bulk.java#L71C1-L74C27

Might be completed like :

var options = new ReplaceOptions();
if (operation.getValue().asDocument().get("upsert") != null
  && operation.getValue().asDocument().get("upsert").isBoolean()) {
  options.upsert(operation.getValue().asDocument().get("upsert").asBoolean().getValue());
}
docWriteRequest = new ReplaceOneModel<>(
  operation.getValue().asDocument().get("filter").asDocument(),
  operation.getValue().asDocument().get("replacement").asDocument(),
  options
);