Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB - Batch Size On Aggregate Options & Find Options #12489

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class AggregateOptions {
private boolean bypassDocumentValidation;
private Collation collation;
private String comment;
private int batchSize;

/**
* Enables writing to temporary files. A null value indicates that it's unspecified.
Expand Down Expand Up @@ -114,6 +115,23 @@ public AggregateOptions hint(Bson hint) {
return this;
}

/**
* Sets the number of documents to return per batch.
*
* <p>
* Overrides the {@link org.reactivestreams.Subscription#request(long)} value for setting the batch size, allowing for fine
* grained
* control over the underlying cursor.
* </p>
*
* @param size the batch size
* @return this
*/
public AggregateOptions batchSize(int size) {
this.batchSize = size;
return this;
}

public <T> AggregatePublisher<T> apply(AggregatePublisher<T> stream) {
AggregatePublisher<T> publisher = stream;

Expand All @@ -134,6 +152,9 @@ public <T> AggregatePublisher<T> apply(AggregatePublisher<T> stream) {
if (maxTime > 0) {
publisher.maxAwaitTime(maxTime, maxTimeUnit);
}
if (batchSize > 0) {
publisher.batchSize(batchSize);
}
return publisher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class FindOptions {
private boolean showRecordId;
private long maxAwaitTime;
private TimeUnit maxAwaitTimeUnit;
private int batchSize;

/**
* Sets the query filter to apply to the query.
Expand Down Expand Up @@ -250,6 +251,23 @@ public FindOptions showRecordId(boolean showRecordId) {
return this;
}

/**
* Sets the number of documents to return per batch.
*
* <p>
* Overrides the {@link org.reactivestreams.Subscription#request(long)} value for setting the batch size, allowing for fine
* grained
* control over the underlying cursor.
* </p>
*
* @param size the batch size
* @return this
*/
public FindOptions batchSize(int size) {
this.batchSize = size;
return this;
}

public <T> FindPublisher<T> apply(FindPublisher<T> stream) {
FindPublisher<T> publisher = stream;
if (filter != null) {
Expand Down Expand Up @@ -306,6 +324,9 @@ public <T> FindPublisher<T> apply(FindPublisher<T> stream) {
if (showRecordId) {
publisher = publisher.showRecordId(true);
}
if (batchSize > 0) {
publisher.batchSize(batchSize);
}
return publisher;

}
Expand Down