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

public static final class MongoSourceBuilder.Stream<T> extends Object
  • Field Details

    • params

      protected com.hazelcast.jet.mongodb.impl.ReadMongoParams<T> params
    • existenceChecks

      protected ResourceChecks existenceChecks
    • name

      protected String 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:

      
        MongoSourceBuilder.stream(name, supplier)
            .collection("myCollection");
       
      This function is an equivalent of calling collection(String, Class) with Document as the second argument.
      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:

      
        MongoSourceBuilder.stream(name, supplier)
            .collection("myCollection", MyDocumentPojo.class);
       
      This function is an equivalent for calling:
      
       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

      @Nonnull public StreamSource<T> build()
      Creates and returns the MongoDB StreamSource which watches the given collection.
    • database

      @Nonnull public MongoSourceBuilder.Stream<T> database(String 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)
      If ResourceChecks.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 is ResourceChecks.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

      @Nonnull public MongoSourceBuilder.Stream<T> project(@Nonnull org.bson.conversions.Bson projection)
      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; use Projections to create projection.
      Returns:
      this builder with projection added
    • sort

      @Nonnull public MongoSourceBuilder.Stream<T> sort(@Nonnull org.bson.conversions.Bson 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. Use Sorts to create sort.
      Returns:
      this builder with aggregate added
    • filter

      @Nonnull public MongoSourceBuilder.Stream<T> filter(@Nonnull 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.

      Example usage:

      
        import static com.mongodb.client.model.Filters.eq;
      
        MongoSourceBuilder.stream(name, supplier)
            .filter(eq("fieldName", 10));
       
      Parameters:
      filter - Bson form of filter. Use Filters to create sort.
      Returns:
      this builder with aggregate added