Skip to content

Commit 99d8fa1

Browse files
committed
Remove mentions of the com.mongodb.Block class
This class is no longer a part of the public API. JAVA-3934
1 parent 9b1670a commit 99d8fa1

File tree

7 files changed

+20
-80
lines changed

7 files changed

+20
-80
lines changed

docs/reference/content/driver/getting-started/quick-start-pojo.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ that can be found with the driver source on github.
2828
- The following import statements:
2929

3030
```java
31-
import com.mongodb.Block;
3231
import com.mongodb.MongoClient;
3332
import com.mongodb.MongoClientSettings;
3433
import com.mongodb.client.MongoCollection;
@@ -220,18 +219,10 @@ To query the collection, you can use the collection's [`find()`]({{< apiref "mon
220219

221220
The following example prints all the Person instances in the collection:
222221
```java
223-
Block<Person> printBlock = new Block<Person>() {
224-
@Override
225-
public void apply(final Person person) {
226-
System.out.println(person);
227-
}
228-
};
229-
230-
collection.find().forEach(printBlock);
222+
collection.find().forEach(System.out::println);
231223
```
232224

233-
The example uses the [`forEach`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/MongoIterable.html#forEach(com.mongodb.Block)" >}}) method on the ``FindIterable``
234-
object to apply a block to each Person and outputs the following:
225+
The example outputs the following:
235226

236227
```bash
237228
Person{id='591dbc2550852fa685b3ad17', name='Ada Byron', age=20, address=Address{street='St James Square', city='London', zip='W1'}}
@@ -272,7 +263,7 @@ Person{id='591dbc2550852fa685b3ad1a', name='Timothy Berners-Lee', age=61,
272263
The following example returns and prints everyone where ``"age" > 30``:
273264

274265
```java
275-
collection.find(gt("age", 30)).forEach(printBlock);
266+
collection.find(gt("age", 30)).forEach(System.out::println);
276267
```
277268

278269
## Update Documents

docs/reference/content/driver/getting-started/quick-start.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import com.mongodb.client.MongoCollection;
4848

4949
import org.bson.Document;
5050
import java.util.Arrays;
51-
import com.mongodb.Block;
5251

5352
import com.mongodb.client.MongoCursor;
5453
import static com.mongodb.client.model.Filters.*;
@@ -356,22 +355,15 @@ The example prints one document:
356355
The following example returns and prints all documents where ``"i" > 50``:
357356

358357
```java
359-
Block<Document> printBlock = new Block<Document>() {
360-
@Override
361-
public void apply(final Document document) {
362-
System.out.println(document.toJson());
363-
}
364-
};
365-
366-
collection.find(gt("i", 50)).forEach(printBlock);
358+
collection.find(gt("i", 50))
359+
.forEach(doc -> System.out.println(doc.toJson()));
367360
```
368361

369-
The example uses the [`forEach`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/MongoIterable.html#forEach(com.mongodb.Block)" >}}) method on the ``FindIterable`` object to apply a block to each document.
370-
371362
To specify a filter for a range, such as ``50 < i <= 100``, you can use the [`and`]({{< apiref "mongodb-driver-core" "com/mongodb/client/model/Filters.html#and(org.bson.conversions.Bson...)" >}}) helper:
372363

373364
```java
374-
collection.find(and(gt("i", 50), lte("i", 100))).forEach(printBlock);
365+
collection.find(and(gt("i", 50), lte("i", 100)))
366+
.forEach(doc -> System.out.println(doc.toJson()));
375367
```
376368

377369
## Update Documents

docs/reference/content/driver/tutorials/aggregation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ The [aggregation pipeline]({{<docsref "core/aggregation-pipeline" >}}) is a fram
1919
- Include the following import statements:
2020

2121
```java
22-
import com.mongodb.Block;
2322
import com.mongodb.client.MongoClients;
2423
import com.mongodb.client.MongoClient;
2524
import com.mongodb.client.MongoCollection;

docs/reference/content/driver/tutorials/change-streams.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ to resume if it encounters a potentially recoverable error.
2424
- Include the following import statements:
2525

2626
```java
27-
import com.mongodb.Block;
2827
import com.mongodb.client.MongoClients;
2928
import com.mongodb.client.MongoClient;
3029

@@ -37,17 +36,6 @@ import com.mongodb.client.model.changestream.FullDocument;
3736
import com.mongodb.client.model.changestream.ChangeStreamDocument;
3837
```
3938

40-
- Include the following code which the examples in the tutorials will use to print the results of the change stream:
41-
42-
```java
43-
Block<ChangeStreamDocument<Document>> printBlock = new Block<>() {
44-
@Override
45-
public void apply(final ChangeStreamDocument<Document> changeStreamDocument) {
46-
System.out.println(changeStreamDocument);
47-
}
48-
};
49-
```
50-
5139
## Connect to a MongoDB Deployment
5240

5341
Connect to a MongoDB deployment and declare and define a `MongoDatabase` and a `MongoCollection` instance.
@@ -70,7 +58,7 @@ To create a change stream use one of the [`MongoCollection.watch()`]({{< apiref
7058
In the following example, the change stream prints out all changes it observes.
7159

7260
```java
73-
collection.watch().forEach(printBlock);
61+
collection.watch().forEach(System.out::println);
7462
```
7563

7664
## Watch the database
@@ -81,7 +69,7 @@ create such a change stream use one of the [`MongoDatabase.watch()`]({{< apiref
8169
In the following example, the change stream prints out all the changes it observes on the given database.
8270

8371
```java
84-
database.watch().forEach(printBlock);
72+
database.watch().forEach(System.out::println);
8573
```
8674

8775
## Watch all databases
@@ -94,7 +82,7 @@ In the following example, the change stream prints out all the changes it observ
9482
connected
9583

9684
```java
97-
mongoClient.watch().forEach(printBlock);
85+
mongoClient.watch().forEach(System.out::println);
9886
```
9987

10088
## Filtering content
@@ -113,5 +101,6 @@ so that the document after the update is included in the results.
113101

114102
```java
115103
collection.watch(asList(Aggregates.match(Filters.in("operationType", asList("insert", "update", "replace", "delete")))))
116-
.fullDocument(FullDocument.UPDATE_LOOKUP).forEach(printBlock);
104+
.fullDocument(FullDocument.UPDATE_LOOKUP)
105+
.forEach(System.out::println);
117106
```

docs/reference/content/driver/tutorials/geospatial-search.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ To support geospatial queries, MongoDB provides various geospatial indexes as we
1919
- Include the following import statements:
2020

2121
```java
22-
import com.mongodb.Block;
2322
import com.mongodb.client.MongoClients;
2423
import com.mongodb.client.MongoClient;
2524
import com.mongodb.client.MongoCollection;
@@ -31,17 +30,6 @@ To support geospatial queries, MongoDB provides various geospatial indexes as we
3130
import org.bson.Document;
3231
```
3332

34-
- Include the following code which the examples in the tutorials will use to print the results of the geospatial search:
35-
36-
```java
37-
Block<Document> printBlock = new Block<Document>() {
38-
@Override
39-
public void apply(final Document document) {
40-
System.out.println(document.toJson());
41-
}
42-
};
43-
```
44-
4533
## Connect to a MongoDB Deployment
4634

4735
Connect to a MongoDB deployment and declare and define a `MongoDatabase` instance.
@@ -75,5 +63,6 @@ The following example returns documents that are at least 1000 meters from and a
7563

7664
```java
7765
Point refPoint = new Point(new Position(-73.9667, 40.78));
78-
collection.find(Filters.near("contact.location", refPoint, 5000.0, 1000.0)).forEach(printBlock);
66+
collection.find(Filters.near("contact.location", refPoint, 5000.0, 1000.0))
67+
.forEach(doc -> System.out.println(doc.toJson()));
7968
```

docs/reference/content/driver/tutorials/gridfs.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ that can be found with the driver source on github.
2323
Include the following import statements:
2424

2525
```java
26-
import com.mongodb.Block;
2726
import com.mongodb.client.MongoClients;
2827
import com.mongodb.client.MongoClient;
2928
import com.mongodb.client.MongoDatabase;
@@ -138,23 +137,15 @@ To find the files stored in the `GridFSBucket` use the [`find`]({{< apiref "mong
138137
The following example prints out the filename of each file stored:
139138

140139
```java
141-
gridFSBucket.find().forEach(
142-
new Block<GridFSFile>() {
143-
public void apply(final GridFSFile gridFSFile) {
144-
System.out.println(gridFSFile.getFilename());
145-
}
146-
});
140+
gridFSBucket.find()
141+
.forEach(gridFSFile -> System.out.println(gridFSFile.getFilename()));
147142
```
148143

149144
You can also provide a custom filter to limit the results returned. The following example prints out the filenames of all files with a "image/png" value set as the contentType in the user defined metadata document:
150145

151146
```java
152-
gridFSBucket.find(eq("metadata.contentType", "image/png")).forEach(
153-
new Block<GridFSFile>() {
154-
public void apply(final GridFSFile gridFSFile) {
155-
System.out.println(gridFSFile.getFilename());
156-
}
157-
});
147+
gridFSBucket.find(eq("metadata.contentType", "image/png"))
148+
.forEach(gridFSFile -> System.out.println(gridFSFile.getFilename()));
158149
```
159150

160151
## Download from GridFS

docs/reference/content/driver/tutorials/text-search.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ The Java driver provides the [`Filters.text()`]({{< apiref "mongodb-driver-core"
2626
- Include the following import statements:
2727

2828
```java
29-
import com.mongodb.Block;
3029
import com.mongodb.client.MongoClients;
3130
import com.mongodb.client.MongoClient;
3231
import com.mongodb.client.MongoCollection;
@@ -40,17 +39,6 @@ The Java driver provides the [`Filters.text()`]({{< apiref "mongodb-driver-core"
4039
import org.bson.Document;
4140
```
4241

43-
- Include the following code which the examples in the tutorials will use to print the results of the text search:
44-
45-
```java
46-
Block<Document> printBlock = new Block<Document>() {
47-
@Override
48-
public void apply(final Document document) {
49-
System.out.println(document.toJson());
50-
}
51-
};
52-
```
53-
5442
## Connect to a MongoDB Deployment
5543

5644
Connect to a MongoDB deployment and declare and define a `MongoDatabase` instance.
@@ -103,7 +91,8 @@ For each matching document, text search assigns a score, representing the releva
10391
```java
10492
collection.find(Filters.text("bakery cafe"))
10593
.projection(Projections.metaTextScore("score"))
106-
.sort(Sorts.metaTextScore("score")).forEach(printBlock);
94+
.sort(Sorts.metaTextScore("score"))
95+
.forEach(doc -> System.out.println(doc.toJson()));
10796
```
10897

10998
### Specify a Text Search Option

0 commit comments

Comments
 (0)