Skip to content

Commit 8d9681e

Browse files
committed
Added bypassDocumentValidation setting to async MapReduceIterable
JAVA-1985
1 parent 0d6d0d9 commit 8d9681e

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

driver-async/src/main/com/mongodb/async/client/MapReduceIterable.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ public interface MapReduceIterable<TResult> extends MongoIterable<TResult> {
160160
*/
161161
MapReduceIterable<TResult> batchSize(int batchSize);
162162

163+
/**
164+
* Sets the bypass document level validation flag.
165+
*
166+
* <p>Note: This only applies when an $out stage is specified</p>.
167+
*
168+
* @param bypassDocumentValidation If true, allows the write to opt-out of document level validation.
169+
* @return this
170+
* @since 3.2
171+
* @mongodb.driver.manual reference/command/mapReduce mapReduce
172+
* @mongodb.server.release 3.2
173+
*/
174+
MapReduceIterable<TResult> bypassDocumentValidation(Boolean bypassDocumentValidation);
175+
163176
/**
164177
* Aggregates documents to a collection according to the specified map-reduce function with the given options, which must specify a
165178
* non-inline result.

driver-async/src/main/com/mongodb/async/client/MapReduceIterableImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class MapReduceIterableImpl<TDocument, TResult> implements MapReduceIterable<TRe
6767
private boolean sharded;
6868
private boolean nonAtomic;
6969
private int batchSize;
70+
private Boolean bypassDocumentValidation;
7071

7172
MapReduceIterableImpl(final MongoNamespace namespace, final Class<TDocument> documentClass, final Class<TResult> resultClass,
7273
final CodecRegistry codecRegistry, final ReadPreference readPreference, final ReadConcern readConcern,
@@ -168,6 +169,13 @@ public MapReduceIterable<TResult> batchSize(final int batchSize) {
168169
return this;
169170
}
170171

172+
173+
@Override
174+
public MapReduceIterable<TResult> bypassDocumentValidation(final Boolean bypassDocumentValidation) {
175+
this.bypassDocumentValidation = bypassDocumentValidation;
176+
return this;
177+
}
178+
171179
@Override
172180
public void toCollection(final SingleResultCallback<Void> callback) {
173181
notNull("callback", callback);
@@ -257,7 +265,8 @@ private MapReduceToCollectionOperation createMapReduceToCollectionOperation() {
257265
.action(action.getValue())
258266
.nonAtomic(nonAtomic)
259267
.sharded(sharded)
260-
.databaseName(databaseName);
268+
.databaseName(databaseName)
269+
.bypassDocumentValidation(bypassDocumentValidation);
261270

262271
if (finalizeFunction != null) {
263272
operation.finalizeFunction(new BsonJavaScript(finalizeFunction));

driver-async/src/test/unit/com/mongodb/async/client/MapReduceIterableSpecification.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class MapReduceIterableSpecification extends Specification {
128128
.action(MapReduceAction.MERGE)
129129
.sharded(true)
130130
.jsMode(true)
131+
.bypassDocumentValidation(true)
131132
mapReduceIterable.into([]) { result, t -> }
132133

133134
def operation = executor.getWriteOperation() as MapReduceToCollectionOperation
@@ -145,6 +146,7 @@ class MapReduceIterableSpecification extends Specification {
145146
.action(MapReduceAction.MERGE.getValue())
146147
.jsMode(true)
147148
.sharded(true)
149+
.bypassDocumentValidation(true)
148150

149151
then: 'should use the overrides'
150152
expect operation, isTheSameAs(expectedOperation)

0 commit comments

Comments
 (0)