com.mongodb.reactivestreams.client.AggregatePublisher Maven / Gradle / Ivy
Show all versions of mongodb-driver-reactivestreams Show documentation
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mongodb.reactivestreams.client;
import com.mongodb.ExplainVerbosity;
import com.mongodb.annotations.Alpha;
import com.mongodb.annotations.Reason;
import com.mongodb.client.cursor.TimeoutMode;
import com.mongodb.client.model.Collation;
import com.mongodb.lang.Nullable;
import org.bson.BsonValue;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.reactivestreams.Publisher;
import java.util.concurrent.TimeUnit;
/**
* Publisher for aggregate.
*
* @param The type of the result.
* @since 1.0
*/
public interface AggregatePublisher extends Publisher {
/**
* Enables writing to temporary files. A null value indicates that it's unspecified.
*
* @param allowDiskUse true if writing to temporary files is enabled
* @return this
* @mongodb.driver.manual reference/command/aggregate/ Aggregation
*/
AggregatePublisher allowDiskUse(@Nullable Boolean allowDiskUse);
/**
* Sets the maximum execution time on the server for this operation.
*
* @param maxTime the max time
* @param timeUnit the time unit, which may not be null
* @return this
* @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
*/
AggregatePublisher maxTime(long maxTime, TimeUnit timeUnit);
/**
* The maximum amount of time for the server to wait on new documents to satisfy a {@code $changeStream} aggregation.
*
* A zero value will be ignored.
*
* @param maxAwaitTime the max await time
* @param timeUnit the time unit to return the result in
* @return the maximum await execution time in the given time unit
* @mongodb.server.release 3.6
* @since 1.6
*/
AggregatePublisher maxAwaitTime(long maxAwaitTime, TimeUnit timeUnit);
/**
* Sets the bypass document level validation flag.
*
* Note: This only applies when an $out stage is specified
.
*
* @param bypassDocumentValidation If true, allows the write to opt-out of document level validation.
* @return this
* @since 1.2
* @mongodb.driver.manual reference/command/aggregate/ Aggregation
* @mongodb.server.release 3.2
*/
AggregatePublisher bypassDocumentValidation(@Nullable Boolean bypassDocumentValidation);
/**
* Aggregates documents according to the specified aggregation pipeline, which must end with a $out stage.
*
* @return an empty publisher that indicates when the operation has completed
* @mongodb.driver.manual aggregation/ Aggregation
*/
Publisher toCollection();
/**
* Sets the collation options
*
* A null value represents the server default.
* @param collation the collation options to use
* @return this
* @since 1.3
* @mongodb.server.release 3.4
*/
AggregatePublisher collation(@Nullable Collation collation);
/**
* Sets the comment for this operation. A null value means no comment is set.
*
* @param comment the comment
* @return this
* @mongodb.server.release 3.6
* @since 1.7
*/
AggregatePublisher comment(@Nullable String comment);
/**
* Sets the comment for this operation. A null value means no comment is set.
*
* The comment can be any valid BSON type for server versions 4.4 and above.
* Server versions between 3.6 and 4.2 only support string as comment,
* and providing a non-string type will result in a server-side error.
*
* @param comment the comment
* @return this
* @since 4.6
* @mongodb.server.release 3.6
*/
AggregatePublisher comment(@Nullable BsonValue comment);
/**
* Sets the hint for which index to use. A null value means no hint is set.
*
* @param hint the hint
* @return this
* @mongodb.server.release 3.6
* @since 1.7
*/
AggregatePublisher hint(@Nullable Bson hint);
/**
* Sets the hint for which index to use. A null value means no hint is set.
*
* Note: If {@link AggregatePublisher#hint(Bson)} is set that will be used instead of any hint string.
*
* @param hint the name of the index which should be used for the operation
* @return this
* @since 4.4
*/
AggregatePublisher hintString(@Nullable String hint);
/**
* Add top-level variables to the aggregation.
*
* For MongoDB 5.0+, the aggregate command accepts a {@code let} option. This option is a document consisting of zero or more
* fields representing variables that are accessible to the aggregation pipeline. The key is the name of the variable and the value is
* a constant in the aggregate expression language. Each parameter name is then usable to access the value of the corresponding
* expression with the "$$" syntax within aggregate expression contexts which may require the use of $expr or a pipeline.
*
*
* @param variables the variables
* @return this
* @since 4.3
* @mongodb.server.release 5.0
*/
AggregatePublisher let(@Nullable Bson variables);
/**
* Sets the number of documents to return per batch.
*
* Overrides the {@link org.reactivestreams.Subscription#request(long)} value for setting the batch size, allowing for fine-grained
* control over the underlying cursor.
*
* @param batchSize the batch size
* @return this
* @since 1.8
* @mongodb.driver.manual reference/method/cursor.batchSize/#cursor.batchSize Batch Size
*/
AggregatePublisher batchSize(int batchSize);
/**
* Sets the timeoutMode for the cursor.
*
*
* Requires the {@code timeout} to be set, either in the {@link com.mongodb.MongoClientSettings},
* via {@link MongoDatabase} or via {@link MongoCollection}
*
*
* If the {@code timeout} is set then:
*
* - For non-tailable cursors, the default value of timeoutMode is {@link TimeoutMode#CURSOR_LIFETIME}
* - For tailable cursors, the default value of timeoutMode is {@link TimeoutMode#ITERATION} and its an error
* to configure it as: {@link TimeoutMode#CURSOR_LIFETIME}
*
* @param timeoutMode the timeout mode
* @return this
* @since 5.2
*/
@Alpha(Reason.CLIENT)
AggregatePublisher timeoutMode(TimeoutMode timeoutMode);
/**
* Helper to return a publisher limited to the first result.
*
* @return a Publisher which will contain a single item.
* @since 1.8
*/
Publisher first();
/**
* Explain the execution plan for this operation with the server's default verbosity level
*
* @return the execution plan
* @since 4.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.6
*/
Publisher explain();
/**
* Explain the execution plan for this operation with the given verbosity level
*
* @param verbosity the verbosity of the explanation
* @return the execution plan
* @since 4.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.6
*/
Publisher explain(ExplainVerbosity verbosity);
/**
* Explain the execution plan for this operation with the server's default verbosity level
*
* @param the type of the document class
* @param explainResultClass the document class to decode into
* @return the execution plan
* @since 4.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.6
*/
Publisher explain(Class explainResultClass);
/**
* Explain the execution plan for this operation with the given verbosity level
*
* @param the type of the document class
* @param explainResultClass the document class to decode into
* @param verbosity the verbosity of the explanation
* @return the execution plan
* @since 4.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.6
*/
Publisher explain(Class explainResultClass, ExplainVerbosity verbosity);
}