print using lamda expression
@@ -32,17 +32,6 @@ The [aggregation pipeline]({{<docsref "core/aggregation-pipeline" >}}) is a fram
import org.bson.Document;
```
-- Include the following code which the examples in the tutorials will use to print the results of the aggregation:
-
- ```java
- Block<Document> printBlock = new Block<Document>() {
- @Override
- public void apply(final Document document) {
- System.out.println(document.toJson());
- }
- };
- ```
-
## Connect to a MongoDB Deployment
Connect to a MongoDB deployment and declare and define a `MongoDatabase` and a `MongoCollection` instances.
@@ -73,7 +62,7 @@ collection.aggregate(
Aggregates.match(Filters.eq("categories", "Bakery")),
Aggregates.group("$stars", Accumulators.sum("count", 1))
)
-).forEach(printBlock);
+).forEach(doc -> System.out.println(doc.toJson()));
```
### Use Aggregation Expressions
@@ -98,7 +87,7 @@ collection.aggregate(
)
)
)
-).forEach(printBlock);
+).forEach(doc -> System.out.println(doc.toJson()));
```
### Explain an Aggregation
