[DOCS-13638] Java driver docs refer to old MongoIterable#forEach(Block<T>) Created: 11/May/20  Updated: 29/Oct/23  Resolved: 16/Jun/20

Status: Closed
Project: Documentation
Component/s: drivers
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Torsten Spindler Assignee: Christopher Cho
Resolution: Fixed Votes: 0
Labels: java-driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 3 years, 34 weeks, 4 days ago
Story Points: 2

 Description   

Description

Hello,

our documentation pages at https://docs.mongodb.com/guides/server/read/ for Java and also http://mongodb.github.io/mongo-java-driver/4.0/driver/tutorials/perform-read-operations/ refer to the old forEach printBlock method, which no longer works.

I worked around the issue via the built-in Java 8 forEach and this consumer:

		Consumer<Document> printBlock = new Consumer<Document>() {
		    public void accept(final Document doc) {
		        System.out.println(doc.toJson());
		    };
		};

Scope of changes

Impact to Other Docs

MVP (Work and Date)

Resources (Scope or Design Docs, Invision, etc.)



 Comments   
Comment by Githook User [ 13/Jun/20 ]

Author:

{'name': 'Chris Cho', 'email': 'chris.cho@10gen.com', 'username': 'ccho-mongodb'}

Message: DOCS-13638: replace Block with Consumer
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/433c1785cf7b0a1fc4dad66d6bc410b49e7d3d7d

Comment by Cloud GitHub Webhooks [ 13/Jun/20 ]

jyemin merged a pull request (DOCS-13638 replace Block with Consumer) into the following branch:
master: 433c1785cf7b0a1fc4dad66d6bc410b49e7d3d7d

Comment by Christopher Cho [ 13/May/20 ]

Guides PR:

https://github.com/10gen/docs-tutorials/pull/153

 

Java docs PR:

https://github.com/mongodb/mongo-java-driver/pull/546

Comment by Jeffrey Yemin [ 12/May/20 ]

It's an issue. Since the 3.x driver supports Java 6+, and Iterable.forEach was added in Java 8, the driver's MongoIterable interface defined our own forEach method that used this Block interface that the driver itself defined. But when running on Java 8, you automatically pick up Iterable's version, which uses an interface called Consumer. In the 4.0 driver we got rid of the driver's forEach method, and now you have to use the one from Iterable. So all the printBlock code should be updated to use Consumer instead of Block

Generated at Thu Feb 08 08:08:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.