Skip to content

Commit 1a30002

Browse files
committed
Make aggretate return a list of document
Signed-off-by: Otavio Santana <[email protected]>
1 parent 72a210a commit 1a30002

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

mongodb-driver/src/main/java/org/eclipse/jnosql/communication/mongodb/document/MongoDBDocumentCollectionManager.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
import jakarta.nosql.document.DocumentEntity;
3030
import jakarta.nosql.document.DocumentQuery;
3131
import org.bson.BsonDocument;
32+
import org.bson.BsonValue;
3233
import org.bson.Document;
3334
import org.bson.conversions.Bson;
3435
import org.eclipse.jnosql.communication.document.Documents;
3536

3637
import java.time.Duration;
3738
import java.util.Collections;
39+
import java.util.HashMap;
3840
import java.util.List;
3941
import java.util.Map;
4042
import java.util.Objects;
@@ -187,16 +189,12 @@ public long delete(String collectionName, Bson filter) {
187189
* @return the number of documents deleted.
188190
* @throws NullPointerException when filter or collectionName is null
189191
*/
190-
public Map<String, Object> aggregate(String collectionName, List<Bson> pipeline) {
192+
public Stream<List<jakarta.nosql.document.Document>> aggregate(String collectionName, List<Bson> pipeline) {
191193
Objects.requireNonNull(pipeline, "filter is required");
192194
Objects.requireNonNull(collectionName, "collectionName is required");
193195
MongoCollection<Document> collection = mongoDatabase.getCollection(collectionName);
194196
AggregateIterable<Document> aggregate = collection.aggregate(pipeline);
195-
for (Document document : aggregate) {
196-
BsonDocument bson = document.toBsonDocument();
197-
System.out.println(bson);
198-
}
199-
return Collections.emptyMap();
197+
return stream(aggregate.spliterator(), false).map(MongoDBUtils::of);
200198
}
201199

202200
/**

0 commit comments

Comments
 (0)