Skip to content

Commit ad29f9d

Browse files
committed
Changed signatures of aggregate and mapReduce to return TDocument iterables instead of Document, to be consistent with find
1 parent 16efab3 commit ad29f9d

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public interface MongoCollection<TDocument> {
201201
* @return an iterable containing the result of the aggregation operation
202202
* @mongodb.driver.manual aggregation/ Aggregation
203203
*/
204-
AggregateIterable<Document> aggregate(List<? extends Bson> pipeline);
204+
AggregateIterable<TDocument> aggregate(List<? extends Bson> pipeline);
205205

206206
/**
207207
* Aggregates documents according to the specified aggregation pipeline. If the pipeline ends with a $out stage, the returned
@@ -224,7 +224,7 @@ public interface MongoCollection<TDocument> {
224224
* @return an iterable containing the result of the map-reduce operation
225225
* @mongodb.driver.manual reference/command/mapReduce/ map-reduce
226226
*/
227-
MapReduceIterable<Document> mapReduce(String mapFunction, String reduceFunction);
227+
MapReduceIterable<TDocument> mapReduce(String mapFunction, String reduceFunction);
228228

229229
/**
230230
* Aggregates documents according to the specified map-reduce function.

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@
7979

8080
class MongoCollectionImpl<TDocument> implements MongoCollection<TDocument> {
8181
private final MongoNamespace namespace;
82-
private final Class<TDocument> clazz;
82+
private final Class<TDocument> documentClass;
8383
private final ReadPreference readPreference;
8484
private final CodecRegistry codecRegistry;
8585
private final WriteConcern writeConcern;
8686
private final AsyncOperationExecutor executor;
8787

88-
MongoCollectionImpl(final MongoNamespace namespace, final Class<TDocument> clazz, final CodecRegistry codecRegistry,
88+
MongoCollectionImpl(final MongoNamespace namespace, final Class<TDocument> documentClass, final CodecRegistry codecRegistry,
8989
final ReadPreference readPreference, final WriteConcern writeConcern, final AsyncOperationExecutor executor) {
9090
this.namespace = notNull("namespace", namespace);
91-
this.clazz = notNull("clazz", clazz);
91+
this.documentClass = notNull("clazz", documentClass);
9292
this.codecRegistry = notNull("codecRegistry", codecRegistry);
9393
this.readPreference = notNull("readPreference", readPreference);
9494
this.writeConcern = notNull("writeConcern", writeConcern);
@@ -102,7 +102,7 @@ public MongoNamespace getNamespace() {
102102

103103
@Override
104104
public Class<TDocument> getDocumentClass() {
105-
return clazz;
105+
return documentClass;
106106
}
107107

108108
@Override
@@ -127,17 +127,17 @@ public <NewTDocument> MongoCollection<NewTDocument> withDocumentClass(final Clas
127127

128128
@Override
129129
public MongoCollection<TDocument> withCodecRegistry(final CodecRegistry codecRegistry) {
130-
return new MongoCollectionImpl<TDocument>(namespace, clazz, codecRegistry, readPreference, writeConcern, executor);
130+
return new MongoCollectionImpl<TDocument>(namespace, documentClass, codecRegistry, readPreference, writeConcern, executor);
131131
}
132132

133133
@Override
134134
public MongoCollection<TDocument> withReadPreference(final ReadPreference readPreference) {
135-
return new MongoCollectionImpl<TDocument>(namespace, clazz, codecRegistry, readPreference, writeConcern, executor);
135+
return new MongoCollectionImpl<TDocument>(namespace, documentClass, codecRegistry, readPreference, writeConcern, executor);
136136
}
137137

138138
@Override
139139
public MongoCollection<TDocument> withWriteConcern(final WriteConcern writeConcern) {
140-
return new MongoCollectionImpl<TDocument>(namespace, clazz, codecRegistry, readPreference, writeConcern, executor);
140+
return new MongoCollectionImpl<TDocument>(namespace, documentClass, codecRegistry, readPreference, writeConcern, executor);
141141
}
142142

143143
@Override
@@ -172,7 +172,7 @@ public <TResult> DistinctIterable<TResult> distinct(final String fieldName, fina
172172

173173
@Override
174174
public FindIterable<TDocument> find() {
175-
return find(new BsonDocument(), clazz);
175+
return find(new BsonDocument(), documentClass);
176176
}
177177

178178
@Override
@@ -182,7 +182,7 @@ public <TResult> FindIterable<TResult> find(final Class<TResult> clazz) {
182182

183183
@Override
184184
public FindIterable<TDocument> find(final Bson filter) {
185-
return find(filter, clazz);
185+
return find(filter, documentClass);
186186
}
187187

188188
@Override
@@ -191,8 +191,8 @@ public <TResult> FindIterable<TResult> find(final Bson filter, final Class<TResu
191191
}
192192

193193
@Override
194-
public AggregateIterable<Document> aggregate(final List<? extends Bson> pipeline) {
195-
return aggregate(pipeline, Document.class);
194+
public AggregateIterable<TDocument> aggregate(final List<? extends Bson> pipeline) {
195+
return aggregate(pipeline, documentClass);
196196
}
197197

198198
@Override
@@ -201,8 +201,8 @@ public <TResult> AggregateIterable<TResult> aggregate(final List<? extends Bson>
201201
}
202202

203203
@Override
204-
public MapReduceIterable<Document> mapReduce(final String mapFunction, final String reduceFunction) {
205-
return mapReduce(mapFunction, reduceFunction, Document.class);
204+
public MapReduceIterable<TDocument> mapReduce(final String mapFunction, final String reduceFunction) {
205+
return mapReduce(mapFunction, reduceFunction, documentClass);
206206
}
207207

208208
@Override
@@ -528,7 +528,7 @@ private UpdateResult toUpdateResult(final com.mongodb.bulk.BulkWriteResult resul
528528
}
529529

530530
private Codec<TDocument> getCodec() {
531-
return getCodec(clazz);
531+
return getCodec(documentClass);
532532
}
533533

534534
private <TResult> Codec<TResult> getCodec(final Class<TResult> clazz) {
@@ -540,6 +540,6 @@ private BsonDocument documentToBsonDocument(final TDocument document) {
540540
}
541541

542542
private BsonDocument toBsonDocument(final Bson document) {
543-
return document == null ? null : document.toBsonDocument(clazz, codecRegistry);
543+
return document == null ? null : document.toBsonDocument(documentClass, codecRegistry);
544544
}
545545
}

driver/src/main/com/mongodb/MongoCollectionImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ public <TResult> FindIterable<TResult> find(final Bson filter, final Class<TResu
189189
}
190190

191191
@Override
192-
public AggregateIterable<Document> aggregate(final List<? extends Bson> pipeline) {
193-
return aggregate(pipeline, Document.class);
192+
public AggregateIterable<TDocument> aggregate(final List<? extends Bson> pipeline) {
193+
return aggregate(pipeline, documentClass);
194194
}
195195

196196
@Override
@@ -200,8 +200,8 @@ public <TResult> AggregateIterable<TResult> aggregate(final List<? extends Bson>
200200
}
201201

202202
@Override
203-
public MapReduceIterable<Document> mapReduce(final String mapFunction, final String reduceFunction) {
204-
return mapReduce(mapFunction, reduceFunction, Document.class);
203+
public MapReduceIterable<TDocument> mapReduce(final String mapFunction, final String reduceFunction) {
204+
return mapReduce(mapFunction, reduceFunction, documentClass);
205205
}
206206

207207
@Override

driver/src/main/com/mongodb/client/MongoCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public interface MongoCollection<TDocument> {
199199
* @mongodb.driver.manual aggregation/ Aggregation
200200
* @mongodb.server.release 2.2
201201
*/
202-
AggregateIterable<Document> aggregate(List<? extends Bson> pipeline);
202+
AggregateIterable<TDocument> aggregate(List<? extends Bson> pipeline);
203203

204204
/**
205205
* Aggregates documents according to the specified aggregation pipeline.
@@ -221,7 +221,7 @@ public interface MongoCollection<TDocument> {
221221
* @return an iterable containing the result of the map-reduce operation
222222
* @mongodb.driver.manual reference/command/mapReduce/ map-reduce
223223
*/
224-
MapReduceIterable<Document> mapReduce(String mapFunction, String reduceFunction);
224+
MapReduceIterable<TDocument> mapReduce(String mapFunction, String reduceFunction);
225225

226226
/**
227227
* Aggregates documents according to the specified map-reduce function.

0 commit comments

Comments
 (0)