Interface AggregateIterable<TResult>
- Type Parameters:
TResult- The type of the result.
- All Superinterfaces:
Iterable<TResult>,MongoIterable<TResult>
- Since:
- 3.0
- MongoDB documentation
- Aggregation
-
Method Summary
Modifier and TypeMethodDescriptionallowDiskUse(Boolean allowDiskUse) Enables writing to temporary files.batchSize(int batchSize) Sets the number of documents to return per batch.bypassDocumentValidation(Boolean bypassDocumentValidation) Sets the bypass document level validation flag.collation(com.mongodb.client.model.Collation collation) Sets the collation optionsSets the comment for this operation.comment(org.bson.BsonValue comment) Sets the comment for this operation.cursor()Aggregates documents according to the specified aggregation pipeline.org.bson.Documentexplain()Explain the execution plan for this operation with the server's default verbosity levelorg.bson.Documentexplain(com.mongodb.ExplainVerbosity verbosity) Explain the execution plan for this operation with the given verbosity level<E> EExplain the execution plan for this operation with the server's default verbosity level<E> EExplain the execution plan for this operation with the given verbosity levelhint(org.bson.conversions.Bson hint) Sets the hint for which index to use.hintString(String hint) Sets the hint to apply.iterator()Aggregates documents according to the specified aggregation pipeline.let(org.bson.conversions.Bson variables) Add top-level variables to the aggregation.maxAwaitTime(long maxAwaitTime, TimeUnit timeUnit) The maximum amount of time for the server to wait on new documents to satisfy a$changeStreamaggregation.Sets the maximum execution time on the server for this operation.timeoutMode(com.mongodb.client.cursor.TimeoutMode timeoutMode) Sets the timeoutMode for the cursor.voidAggregates documents according to the specified aggregation pipeline, which must end with an$outor$mergestage.Methods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface com.mongodb.client.MongoIterable
first, into, map
-
Method Details
-
toCollection
void toCollection()Aggregates documents according to the specified aggregation pipeline, which must end with an$outor$mergestage. This method is the preferred alternative toiterator(),cursor(), because this method does what is explicitly requested without executing implicit operations.- Throws:
IllegalStateException- if the pipeline does not end with an$outor$mergestage- Since:
- 3.4
- MongoDB documentation
- $out stage
- $merge stage
-
iterator
MongoCursor<TResult> iterator()Aggregates documents according to the specified aggregation pipeline.-
If the aggregation pipeline ends with an
$outor$mergestage, then finds all documents in the affected namespace and returns aMongoCursorover them. You may want to usetoCollection()instead. -
Otherwise, returns a
MongoCursorproducing no elements.
- Specified by:
iteratorin interfaceIterable<TResult>- Specified by:
iteratorin interfaceMongoIterable<TResult>- Returns:
- A
MongoCursorthat must be closed.
-
If the aggregation pipeline ends with an
-
cursor
MongoCursor<TResult> cursor()Aggregates documents according to the specified aggregation pipeline.-
If the aggregation pipeline ends with an
$outor$mergestage, then finds all documents in the affected namespace and returns aMongoCursorover them. You may want to usetoCollection()instead. -
Otherwise, returns a
MongoCursorproducing no elements.
- Specified by:
cursorin interfaceMongoIterable<TResult>- Returns:
- a cursor equivalent to that returned from
MongoIterable.iterator().
-
If the aggregation pipeline ends with an
-
allowDiskUse
Enables writing to temporary files. A null value indicates that it's unspecified.- Parameters:
allowDiskUse- true if writing to temporary files is enabled- Returns:
- this
- MongoDB documentation
- Aggregation
-
batchSize
Sets the number of documents to return per batch.- Specified by:
batchSizein interfaceMongoIterable<TResult>- Parameters:
batchSize- the batch size- Returns:
- this
- MongoDB documentation
- Batch Size
-
timeoutMode
@Alpha(CLIENT) AggregateIterable<TResult> timeoutMode(com.mongodb.client.cursor.TimeoutMode timeoutMode) Sets the timeoutMode for the cursor.Requires the
timeoutto be set, either in theMongoClientSettings, viaMongoDatabaseor viaMongoCollectionIf the
timeoutis set then:- For non-tailable cursors, the default value of timeoutMode is
TimeoutMode.CURSOR_LIFETIME - For tailable cursors, the default value of timeoutMode is
TimeoutMode.ITERATIONand its an error to configure it as:TimeoutMode.CURSOR_LIFETIME
Will error if the timeoutMode is set to
TimeoutMode.ITERATIONand the pipeline contains either an$outor a$mergestage.- Parameters:
timeoutMode- the timeout mode- Returns:
- this
- Since:
- 5.2
- For non-tailable cursors, the default value of timeoutMode is
-
maxTime
Sets the maximum execution time on the server for this operation.- Parameters:
maxTime- the max timetimeUnit- the time unit, which may not be null- Returns:
- this
- MongoDB documentation
- Max Time
-
maxAwaitTime
The maximum amount of time for the server to wait on new documents to satisfy a$changeStreamaggregation.A zero value will be ignored.
- Parameters:
maxAwaitTime- the max await timetimeUnit- the time unit to return the result in- Returns:
- the maximum await execution time in the given time unit
- Since:
- 3.6
- Since server release
- 3.6
-
bypassDocumentValidation
Sets the bypass document level validation flag.Note: This only applies when an $out or $merge stage is specified
.- Parameters:
bypassDocumentValidation- If true, allows the write to opt-out of document level validation.- Returns:
- this
- Since:
- 3.2
- MongoDB documentation
- Aggregation
- Since server release
- 3.2
-
collation
Sets the collation optionsA null value represents the server default.
- Parameters:
collation- the collation options to use- Returns:
- this
- Since:
- 3.4
- Since server release
- 3.4
-
comment
Sets the comment for this operation. A null value means no comment is set.- Parameters:
comment- the comment- Returns:
- this
- Since:
- 3.6
- Since server release
- 3.6
-
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.
- Parameters:
comment- the comment- Returns:
- this
- Since:
- 4.6
- Since server release
- 3.6
-
hint
Sets the hint for which index to use. A null value means no hint is set.- Parameters:
hint- the hint- Returns:
- this
- Since:
- 3.6
- Since server release
- 3.6
-
hintString
Sets the hint to apply.Note: If
hint(Bson)is set that will be used instead of any hint string.- Parameters:
hint- the name of the index which should be used for the operation- Returns:
- this
- Since:
- 4.4
-
let
Add top-level variables to the aggregation.For MongoDB 5.0+, the aggregate command accepts a
letoption. 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.- Parameters:
variables- the variables- Returns:
- this
- Since:
- 4.3
- Since server release
- 5.0
-
explain
org.bson.Document explain()Explain the execution plan for this operation with the server's default verbosity level- Returns:
- the execution plan
- Since:
- 4.2
- MongoDB documentation
- reference/command/explain/
- Since server release
- 3.6
-
explain
org.bson.Document explain(com.mongodb.ExplainVerbosity verbosity) Explain the execution plan for this operation with the given verbosity level- Parameters:
verbosity- the verbosity of the explanation- Returns:
- the execution plan
- Since:
- 4.2
- MongoDB documentation
- reference/command/explain/
- Since server release
- 3.6
-
explain
Explain the execution plan for this operation with the server's default verbosity level- Type Parameters:
E- the type of the document class- Parameters:
explainResultClass- the document class to decode into- Returns:
- the execution plan
- Since:
- 4.2
- MongoDB documentation
- reference/command/explain/
- Since server release
- 3.6
-
explain
Explain the execution plan for this operation with the given verbosity level- Type Parameters:
E- the type of the document class- Parameters:
explainResultClass- the document class to decode intoverbosity- the verbosity of the explanation- Returns:
- the execution plan
- Since:
- 4.2
- MongoDB documentation
- reference/command/explain/
- Since server release
- 3.6
-