Modifier and Type | Method and Description |
---|---|
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 MongoDB
Sink for the Pipeline API. |
static <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 MongoDB
Sink for the Pipeline API. |
static Sink<org.bson.Document> |
mongodb(DataConnectionRef dataConnectionRef,
String database,
String collection)
|
static Sink<org.bson.Document> |
mongodb(String connectionString,
String database,
String collection)
|
@Beta public static <T> MongoSinkBuilder<T> builder(@Nonnull Class<T> itemClass, @Nonnull SupplierEx<com.mongodb.client.MongoClient> clientSupplier)
Sink
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);
T
- type of the items the sink acceptsclientSupplier
- MongoDB client supplieritemClass
- type of document that will be saved@Beta public static <T> MongoSinkBuilder<T> builder(@Nonnull Class<T> itemClass, @Nonnull DataConnectionRef dataConnectionRef)
Sink
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.
T
- type of the items the sink acceptsdataConnectionRef
- reference to mongo data connectionitemClass
- type of document that will be saved@Beta public static Sink<org.bson.Document> mongodb(@Nonnull String connectionString, @Nonnull String database, @Nonnull String collection)
builder(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);
connectionString
- connection string to MongoDB instancedatabase
- database to which the documents will be put intocollection
- collection to which the documents will be put into@Beta public static Sink<org.bson.Document> mongodb(@Nonnull DataConnectionRef dataConnectionRef, @Nonnull String database, @Nonnull String collection)
builder(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);
dataConnectionRef
- reference to some mongo data connectiondatabase
- database to which the documents will be put intocollection
- collection to which the documents will be put intoCopyright © 2024 Hazelcast, Inc.. All rights reserved.