Class MongoSinks
- Since:
- 5.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> MongoSinkBuilder<T>
builder
(Class<T> itemClass, SupplierEx<com.mongodb.client.MongoClient> clientSupplier) Returns a builder object that offers a step-by-step fluent API to build a custom MongoDBSink
for the Pipeline API.static <T> MongoSinkBuilder<T>
builder
(Class<T> itemClass, DataConnectionRef dataConnectionRef) Returns a builder object that offers a step-by-step fluent API to build a custom MongoDBSink
for the Pipeline API.static Sink<org.bson.Document>
mongodb
(DataConnectionRef dataConnectionRef, String database, String collection) static Sink<org.bson.Document>
-
Method Details
-
builder
public static <T> MongoSinkBuilder<T> builder(@Nonnull Class<T> itemClass, @Nonnull SupplierEx<com.mongodb.client.MongoClient> clientSupplier) Returns a builder object that offers a step-by-step fluent API to build a custom MongoDBSink
for the Pipeline API.The sink inserts or replaces the items it receives to specified collection using
MongoCollection.bulkWrite(java.util.List<? extends com.mongodb.client.model.WriteModel<? extends TDocument>>)
.All operations are done within transaction if processing guarantee of the job is
ProcessingGuarantee.EXACTLY_ONCE
.All writes are done using default MongoDB codecs with POJO class codec added.
Example usage:
Sink<Document> mongoSink = MongoSinks.builder( Document.class, () -> MongoClients.create("mongodb://127.0.0.1:27017") ) .into("myDatabase", "myCollection") .identifyDocumentBy("_id", doc -> doc.get("_id")) .build() ); Pipeline p = Pipeline.create(); (...) someStage.writeTo(mongoSink);
- Type Parameters:
T
- type of the items the sink accepts- Parameters:
clientSupplier
- MongoDB client supplieritemClass
- type of document that will be saved- Since:
- 5.3
-
builder
public static <T> MongoSinkBuilder<T> builder(@Nonnull Class<T> itemClass, @Nonnull DataConnectionRef dataConnectionRef) Returns a builder object that offers a step-by-step fluent API to build a custom MongoDBSink
for the Pipeline API.The sink inserts or replaces the items it receives to specified collection using
MongoCollection.bulkWrite(java.util.List<? extends com.mongodb.client.model.WriteModel<? extends TDocument>>)
.All operations are done within transaction if processing guarantee of the job is
ProcessingGuarantee.EXACTLY_ONCE
.All writes are done using default MongoDB codecs with POJO class codec added.
Example usage:
Sink<Document> mongoSink = MongoSinks.builder( Document.class, dataConnectionRef("someMongoDB") ) .into("myDatabase", "myCollection") .identifyDocumentBy("_id", doc -> doc.get("_id")) .build() ); Pipeline p = Pipeline.create(); (...) someStage.writeTo(mongoSink);
Connector will use provided data connection reference to obtain an instance of
MongoClient
. Depending on the configuration this client may be shared between processors or not.- Type Parameters:
T
- type of the items the sink accepts- Parameters:
dataConnectionRef
- reference to mongo data connectionitemClass
- type of document that will be saved- Since:
- 5.3
-
mongodb
public static Sink<org.bson.Document> mongodb(@Nonnull String connectionString, @Nonnull String database, @Nonnull String collection) Convenience forbuilder(java.lang.Class<T>, com.hazelcast.function.SupplierEx<com.mongodb.client.MongoClient>)
. Example usage:Sink<Document> mongoSink = MongoSinks.mongodb( "mongodb://127.0.0.1:27017", "myDatabase", "myCollection" ); Pipeline p = Pipeline.create(); (...) someStage.writeTo(mongoSink);
- Parameters:
connectionString
- connection string to MongoDB instancedatabase
- database to which the documents will be put intocollection
- collection to which the documents will be put into- Since:
- 5.3
-
mongodb
public static Sink<org.bson.Document> mongodb(@Nonnull DataConnectionRef dataConnectionRef, @Nonnull String database, @Nonnull String collection) Convenience forbuilder(java.lang.Class<T>, com.hazelcast.function.SupplierEx<com.mongodb.client.MongoClient>)
. Example usage:Sink<Document> mongoSink = MongoSinks.mongodb( dataConnectionRef("someMongoDB"), "myDatabase", "myCollection" ); Pipeline p = Pipeline.create(); (...) someStage.writeTo(mongoSink);
- Parameters:
dataConnectionRef
- reference to some mongo data connectiondatabase
- database to which the documents will be put intocollection
- collection to which the documents will be put into- Since:
- 5.3
-