|
15 | 15 |
|
16 | 16 | package org.eclipse.jnosql.communication.mongodb.document; |
17 | 17 |
|
| 18 | +import com.mongodb.client.AggregateIterable; |
18 | 19 | import com.mongodb.client.FindIterable; |
19 | 20 | import com.mongodb.client.MongoCollection; |
20 | 21 | import com.mongodb.client.MongoDatabase; |
|
33 | 34 | import org.eclipse.jnosql.communication.document.Documents; |
34 | 35 |
|
35 | 36 | import java.time.Duration; |
| 37 | +import java.util.Collections; |
| 38 | +import java.util.List; |
| 39 | +import java.util.Map; |
36 | 40 | import java.util.Objects; |
37 | 41 | import java.util.stream.Stream; |
38 | 42 | import java.util.stream.StreamSupport; |
@@ -175,8 +179,24 @@ public long delete(String collectionName, Bson filter) { |
175 | 179 | return result.getDeletedCount(); |
176 | 180 | } |
177 | 181 |
|
178 | | - public long aggregate(String collectionName, Bson filter) { |
179 | | - return 0L; |
| 182 | + /** |
| 183 | + * Aggregates documents according to the specified aggregation pipeline. |
| 184 | + * |
| 185 | + * @param collectionName the collection name |
| 186 | + * @param pipeline the aggregation pipeline |
| 187 | + * @return the number of documents deleted. |
| 188 | + * @throws NullPointerException when filter or collectionName is null |
| 189 | + */ |
| 190 | + public Map<String, Object> aggregate(String collectionName, List<Bson> pipeline) { |
| 191 | + Objects.requireNonNull(pipeline, "filter is required"); |
| 192 | + Objects.requireNonNull(collectionName, "collectionName is required"); |
| 193 | + MongoCollection<Document> collection = mongoDatabase.getCollection(collectionName); |
| 194 | + 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(); |
180 | 200 | } |
181 | 201 |
|
182 | 202 | /** |
|
0 commit comments