public final class MongoSources extends Object
See MongoSourceBuilder for creating custom MongoDB sources.
| Modifier and Type | Method and Description |
|---|---|
static MongoSourceBuilder.Batch<org.bson.Document> |
batch(DataConnectionRef dataConnectionRef)
Creates as builder for new batch mongo source.
|
static BatchSource<org.bson.Document> |
batch(DataConnectionRef dataConnectionRef,
String database,
String collection,
org.bson.conversions.Bson filter,
org.bson.conversions.Bson projection)
Returns a MongoDB batch source which queries the collection using given
filter and applies the given projection on the documents. |
static BatchSource<org.bson.Document> |
batch(String connectionString,
String database,
String collection,
org.bson.conversions.Bson filter,
org.bson.conversions.Bson projection)
Returns a MongoDB batch source which queries the collection using given
filter and applies the given projection on the documents. |
static MongoSourceBuilder.Batch<org.bson.Document> |
batch(SupplierEx<? extends com.mongodb.client.MongoClient> clientSupplier)
Creates as builder for new batch mongo source.
|
static StreamSource<? extends org.bson.Document> |
stream(String connectionString,
String database,
String collection,
org.bson.Document filter,
org.bson.Document projection)
Returns a MongoDB stream source which watches the changes on the
collection.
|
static MongoSourceBuilder.Stream<org.bson.Document> |
stream(SupplierEx<? extends com.mongodb.client.MongoClient> clientSupplier)
Creates as builder for new stream mongo source.
|
@Beta @Nonnull public static MongoSourceBuilder.Batch<org.bson.Document> batch(@Nonnull SupplierEx<? extends com.mongodb.client.MongoClient> clientSupplier)
MongoSourceBuilder.batch(java.lang.String, com.hazelcast.function.SupplierEx<? extends com.mongodb.client.MongoClient>).
Example usage:
BatchSource<MyDTO> batchSource =
MongoSources.batch(() -> MongoClients.create("mongodb://127.0.0.1:27017"))
.database("myDatabase")
.collection("myCollection", MyDTO.class)
.filter(new Document("age", new Document("$gt", 10)),
.projection(new Document("age", 1))
);
Pipeline p = Pipeline.create();
BatchStage<Document> srcStage = p.readFrom(batchSource);
clientSupplier - a function that creates MongoDB client.@Beta @Nonnull public static MongoSourceBuilder.Batch<org.bson.Document> batch(@Nonnull DataConnectionRef dataConnectionRef)
MongoSourceBuilder.batch(java.lang.String, com.hazelcast.function.SupplierEx<? extends com.mongodb.client.MongoClient>).
Example usage:
BatchSource<Document> batchSource =
MongoSources.batch(dataConnectionRef("mongo"))
.database("myDatabase")
.collection("myCollection")
.filter(new Document("age", new Document("$gt", 10)),
.projection(new Document("age", 1))
);
Pipeline p = Pipeline.create();
BatchStage<Document> srcStage = p.readFrom(batchSource);
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.dataConnectionRef - a reference to mongo data connection@Beta @Nonnull public static BatchSource<org.bson.Document> batch(@Nonnull String connectionString, @Nonnull String database, @Nonnull String collection, @Nullable org.bson.conversions.Bson filter, @Nullable org.bson.conversions.Bson projection)
filter and applies the given projection on the documents.
See MongoSourceBuilder for creating custom MongoDB sources.
Here's an example which queries documents in a collection having the
field age with a value greater than 10 and applies a
projection so that only the age field is returned in the
emitted document.
BatchSource<Document> batchSource =
MongoSources.batch(
"mongodb://127.0.0.1:27017",
"myDatabase",
"myCollection",
new Document("age", new Document("$gt", 10)),
new Document("age", 1)
);
Pipeline p = Pipeline.create();
BatchStage<Document> srcStage = p.readFrom(batchSource);
connectionString - a connection string URI to MongoDB for example:
mongodb://127.0.0.1:27017database - the name of the databasecollection - the name of the collectionfilter - filter object as a Documentprojection - projection object as a Document@Beta @Nonnull public static BatchSource<org.bson.Document> batch(@Nonnull DataConnectionRef dataConnectionRef, @Nonnull String database, @Nonnull String collection, @Nullable org.bson.conversions.Bson filter, @Nullable org.bson.conversions.Bson projection)
filter and applies the given projection on the documents.
See MongoSourceBuilder for creating custom MongoDB sources.
Here's an example which queries documents in a collection having the
field age with a value greater than 10 and applies a
projection so that only the age field is returned in the
emitted document.
BatchSource<Document> batchSource =
MongoSources.batch(
dataConnectionRef("mongoDb"),
"myDatabase",
"myCollection",
new Document("age", new Document("$gt", 10)),
new Document("age", 1)
);
Pipeline p = Pipeline.create();
BatchStage<Document> srcStage = p.readFrom(batchSource);
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.
dataConnectionRef - a reference to some mongo data connectiondatabase - the name of the databasecollection - the name of the collectionfilter - filter object as a Documentprojection - projection object as a Document@Beta @Nonnull public static MongoSourceBuilder.Stream<org.bson.Document> stream(@Nonnull SupplierEx<? extends com.mongodb.client.MongoClient> clientSupplier)
MongoSourceBuilder.stream(java.lang.String, com.hazelcast.function.SupplierEx<? extends com.mongodb.client.MongoClient>).
Example usage:
StreamSource<Document> streamSource =
MongoSources.stream(() -> MongoClients.create("mongodb://127.0.0.1:27017"))
.database("myDatabase")
.collection("myCollection")
.filter(new Document("fullDocument.age", new Document("$gt", 10)),
.projection(new Document("fullDocument.age", 1))
);
Pipeline p = Pipeline.create();
StreamStage<Document> srcStage = p.readFrom(streamSource);
clientSupplier - a function that creates MongoDB client.@Beta @Nonnull public static StreamSource<? extends org.bson.Document> stream(@Nonnull String connectionString, @Nonnull String database, @Nonnull String collection, @Nullable org.bson.Document filter, @Nullable org.bson.Document projection)
filter and projection on the change stream documents.
Change stream is available for replica sets and sharded clusters that use WiredTiger storage engine and replica set protocol version 1 (pv1). Change streams can also be used on deployments which employ MongoDB's encryption-at-rest feature. You cannot watch on system collections and collections in admin, local and config databases.
See MongoSourceBuilder for creating custom MongoDB sources.
Here's an example which streams inserts on a collection having the
field age with a value greater than 10 and applies a
projection so that only the age field is returned in the
emitted document.
StreamSource<? extends Document> streamSource =
MongoSources.stream(
"mongodb://127.0.0.1:27017",
"myDatabase",
"myCollection",
new Document("fullDocument.age", new Document("$gt", 10))
.append("operationType", "insert"),
new Document("fullDocument.age", 1)
);
Pipeline p = Pipeline.create();
StreamSourceStage<? extends Document> srcStage = p.readFrom(streamSource);
connectionString - a connection string URI to MongoDB for example:
mongodb://127.0.0.1:27017database - the name of the databasecollection - the name of the collectionfilter - filter object as a Documentprojection - projection object as a DocumentCopyright © 2023 Hazelcast, Inc.. All rights reserved.