Package com.hazelcast.jet.mongodb
Class MongoSourceBuilder.Stream<T>
java.lang.Object
com.hazelcast.jet.mongodb.MongoSourceBuilder.Stream<T>
- Type Parameters:
T
- type of the queried documents
- Enclosing class:
- MongoSourceBuilder
-
Field Summary
Modifier and TypeFieldDescriptionprotected ResourceChecks
protected boolean
protected String
protected com.hazelcast.jet.mongodb.impl.ReadMongoParams<T>
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Creates and returns the MongoDBStreamSource
which watches the given collection.checkResourceExistence
(ResourceChecks checkResourceExistence) IfResourceChecks.NEVER
, the database and collection will be automatically created on the first usage.MongoSourceBuilder.Stream<org.bson.Document>
collection
(String collectionName) Specifies from which collection connector will read documents.<T_NEW> MongoSourceBuilder.Stream<T_NEW>
collection
(String collectionName, Class<T_NEW> mongoType) Specifies from which collection connector will read documents.filter
(org.bson.conversions.Bson filter) Adds filter aggregate to this builder, which allows to filter documents in MongoDB, without the need to download all documents.forceReadTotalParallelismOne
(boolean forceReadTotalParallelismOne) If set to true, reading will be done in only one thread.<T_NEW> MongoSourceBuilder.Stream<T_NEW>
mapFn
(BiFunctionEx<com.mongodb.client.model.changestream.ChangeStreamDocument<org.bson.Document>, Long, T_NEW> mapFn) project
(org.bson.conversions.Bson projection) Adds a projection aggregate.sort
(org.bson.conversions.Bson sort) Adds sort aggregate to this builder.startAtOperationTime
(org.bson.BsonTimestamp startAtOperationTime) Specifies time from which MongoDB's events will be read.
-
Field Details
-
params
-
existenceChecks
-
name
-
forceReadTotalParallelismOne
protected boolean forceReadTotalParallelismOne
-
-
Method Details
-
collection
@Nonnull public MongoSourceBuilder.Stream<org.bson.Document> collection(@Nonnull String collectionName) Specifies from which collection connector will read documents. If not invoked, then connector will look at all collections in given database.Example usage:
This function is an equivalent of calling collection(String, Class) with Document as the second argument.MongoSourceBuilder.stream(name, supplier) .collection("myCollection");
- Parameters:
collectionName
- Name of the collection that will be queried.- Returns:
- this builder
-
collection
@Nonnull public <T_NEW> MongoSourceBuilder.Stream<T_NEW> collection(@Nonnull String collectionName, @Nonnull Class<T_NEW> mongoType) Specifies from which collection connector will read documents. If not invoked, then connector will look at all collections in given database. All documents read will be automatically parsed to user-defined type using MongoDB's standard codec registry with pojo support added.Example usage:
This function is an equivalent for calling:MongoSourceBuilder.stream(name, supplier) .collection("myCollection", MyDocumentPojo.class);
import static com.hazelcast.jet.mongodb.impl.Mappers.toClass; MongoSourceBuilder.stream(name, supplier) .collection("myCollection") .mapFn(toClass(MyuDocumentPojo.class));
- Parameters:
collectionName
- Name of the collection that will be queried.mongoType
- user defined type to which the document will be parsed.- Returns:
- this builder
-
mapFn
@Nonnull public <T_NEW> MongoSourceBuilder.Stream<T_NEW> mapFn(@Nonnull BiFunctionEx<com.mongodb.client.model.changestream.ChangeStreamDocument<org.bson.Document>, Long, T_NEW> mapFn) - Type Parameters:
T_NEW
- type of the emitted object- Parameters:
mapFn
- transforms the queried document to the desired output object. Second parameter will be the event timestamp.- Returns:
- this builder
-
startAtOperationTime
@Nonnull public MongoSourceBuilder.Stream<T> startAtOperationTime(@Nonnull org.bson.BsonTimestamp startAtOperationTime) Specifies time from which MongoDB's events will be read.It is highly suggested to provide this argument, as it will reduce reading initial state of database.
- Parameters:
startAtOperationTime
- time from which events should be taken into consideration- Returns:
- this builder
-
build
Creates and returns the MongoDBStreamSource
which watches the given collection. -
database
-
forceReadTotalParallelismOne
@Nonnull public MongoSourceBuilder.Stream<T> forceReadTotalParallelismOne(boolean forceReadTotalParallelismOne) If set to true, reading will be done in only one thread.- Parameters:
forceReadTotalParallelismOne
- if true, reading will be done in only one thread.
-
checkResourceExistence
@Nonnull public MongoSourceBuilder.Stream<T> checkResourceExistence(ResourceChecks checkResourceExistence) IfResourceChecks.NEVER
, the database and collection will be automatically created on the first usage. Otherwise, querying for a database or collection that don't exist will cause an error. Default value isResourceChecks.ONCE_PER_JOB
.- Parameters:
checkResourceExistence
- mode of resource existence checks; whether exception should be thrown when database or collection does not exist and when the check will be performed.- Since:
- 5.4
-
project
Adds a projection aggregate. Example use:import static com.mongodb.client.model.Projections.include; MongoSourceBuilder.stream(name, supplier) .projection(include("fieldName"));
- Parameters:
projection
- Bson form of projection; useProjections
to create projection.- Returns:
- this builder with projection added
-
sort
Adds sort aggregate to this builder.Example usage:
import static com.mongodb.client.model.Sorts.ascending; MongoSourceBuilder.stream(name, supplier) .sort(ascending("fieldName"));
- Parameters:
sort
- Bson form of sort. UseSorts
to create sort.- Returns:
- this builder with aggregate added
-
filter
Adds filter aggregate to this builder, which allows to filter documents in MongoDB, without the need to download all documents.Example usage:
import static com.mongodb.client.model.Filters.eq; MongoSourceBuilder.stream(name, supplier) .filter(eq("fieldName", 10));
- Parameters:
filter
- Bson form of filter. UseFilters
to create sort.- Returns:
- this builder with aggregate added
-