Jacob Jona Fahlenkamp created FLINK-39334:
---------------------------------------------
Summary: flink-connector-mongodb fails when write concern is set
to zero
Key: FLINK-39334
URL: https://issues.apache.org/jira/browse/FLINK-39334
Project: Flink
Issue Type: Bug
Components: Connectors / MongoDB
Affects Versions: 1.20.3
Reporter: Jacob Jona Fahlenkamp
When specifying write concern zero, the mongo sink fails. This is because [it
always sets the bypassDocumentValidation
option.|https://github.com/apache/flink-connector-mongodb/blob/main/flink-connector-mongodb/src/main/java/org/apache/flink/connector/mongodb/sink/writer/MongoWriter.java#L221].
But if the write concern is set to zero this is not allowed by the mongo
driver. The fix would be to set the bypassDocumentValidation option only if
it's true.
Reproduction:
{code:java}
@Container
private static final MongoDBContainer MONGO_CONTAINER =
MongoTestUtil.createMongoDBContainer();
@Test
void writeConcernZero() throws Exception {
MongoSink<BsonDocument> sink = MongoSink.<BsonDocument>builder()
.setUri(MONGO_CONTAINER.getConnectionString() + "/?w=0")
.setDatabase("database")
.setCollection("collection")
.setSerializationSchema((doc, context) -> new InsertOneModel<>(doc))
.build();
StreamExecutionEnvironment env =
StreamExecutionEnvironment.getExecutionEnvironment();
env.fromData(new BsonDocument("hello", new BsonString("world")))
.sinkTo(sink);
env.execute();
} {code}
this throws:
{code:java}
com.mongodb.MongoClientException: Specifying bypassDocumentValidation with an
unacknowledged WriteConcern is not supported{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)