Skip to content

Commit 87c76e1

Browse files
authored
optimize aggregate()
The aggregate method can get BsonDocument(s) directly instead getting the iterator of Document(s) first and then convert them back to the BsonDocument(s). https://www.eclipse.org/lists/jnosql-dev/msg00642.html
1 parent 6190f70 commit 87c76e1

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/MongoDBDocumentManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,9 @@ public long delete(String collectionName, Bson filter) {
208208
public Stream<Map<String, BsonValue>> aggregate(String collectionName, List<Bson> pipeline) {
209209
Objects.requireNonNull(pipeline, "filter is required");
210210
Objects.requireNonNull(collectionName, "collectionName is required");
211-
MongoCollection<Document> collection = mongoDatabase.getCollection(collectionName);
212-
AggregateIterable<Document> aggregate = collection.aggregate(pipeline);
213-
return stream(aggregate.spliterator(), false)
214-
.map(Document::toBsonDocument);
211+
MongoCollection<BsonDocument> collection = mongoDatabase.getCollection(collectionName, BsonDocument.class);
212+
AggregateIterable aggregate = collection.aggregate(pipeline);
213+
return stream(aggregate.spliterator(), false);
215214
}
216215

217216
/**

0 commit comments

Comments
 (0)