<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:56:06 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[JAVA-2010] Support the use of Java 8 lambdas and MongoIterable.forEach()</title>
                <link>https://jira.mongodb.org/browse/JAVA-2010</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;The drivers forEach method makes the use of lambda forEach ambiguous:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;            collection.find(filterBson).forEach(doc -&amp;gt; {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;                // do something here&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;            });&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;results in the following compile error&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;   &quot;The method forEach(Block&amp;lt;? super Document&amp;gt;) is ambiguous for the type FindIterable&amp;lt;Document&amp;gt;&quot;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;&lt;b&gt;Update&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3046&quot; title=&quot;Deprecate MongoIterable#forEach&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3046&quot;&gt;&lt;del&gt;JAVA-3046&lt;/del&gt;&lt;/a&gt; addresses the compiler error described above by deprecating &lt;tt&gt;MongoIterable#forEach(Block&amp;lt;T&amp;gt; block)&lt;/tt&gt; so that it can be removed in the next major release.  Once it&apos;s gone the compiler error will no longer occur.  Under this ticket, we address the cursor leak that can occur when using &lt;tt&gt;Iterable#forEach(Consumer&amp;lt;T&amp;gt; consumer&lt;/tt&gt; by overriding that method in every &lt;tt&gt;MongoIterable&lt;/tt&gt; implementation to properly close the &lt;tt&gt;MongoCursor&lt;/tt&gt; even when an exception occurs during the internal iteration of the method.&lt;/p&gt;</description>
                <environment></environment>
        <key id="233464">JAVA-2010</key>
            <summary>Support the use of Java 8 lambdas and MongoIterable.forEach()</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="jeff.yemin@mongodb.com">Jeffrey Yemin</assignee>
                                    <reporter username="andre.defrere@mongodb.com">Andre de Frere</reporter>
                        <labels>
                    </labels>
                <created>Wed, 7 Oct 2015 23:26:56 +0000</created>
                <updated>Mon, 22 Oct 2018 19:11:09 +0000</updated>
                            <resolved>Mon, 22 Oct 2018 14:59:26 +0000</resolved>
                                                    <fixVersion>3.9.0</fixVersion>
                                    <component>API</component>
                                        <votes>3</votes>
                                    <watches>8</watches>
                                                                                                                <comments>
                            <comment id="2038004" author="xgen-internal-githook" created="Mon, 22 Oct 2018 19:11:09 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Jeff Yemin&apos;, &apos;email&apos;: &apos;jeff.yemin@10gen.com&apos;, &apos;username&apos;: &apos;jyemin&apos;}
&lt;p&gt;Message: Override forEach(Consumer&amp;lt;T&amp;gt;) in MongoIterable implementations&lt;/p&gt;

&lt;p&gt;The implementations of this method now all properly close the&lt;br/&gt;
MongoCursor&amp;lt;T&amp;gt; so that cursors are not leaked when the forEach&lt;br/&gt;
method doesn&apos;t complete normally.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-2010&quot; title=&quot;Support the use of Java 8 lambdas and MongoIterable.forEach()&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-2010&quot;&gt;&lt;del&gt;JAVA-2010&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/ef1c166c8efb940febccd331c3348c29191560ec&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/ef1c166c8efb940febccd331c3348c29191560ec&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1148170" author="diablox" created="Wed, 20 Jan 2016 02:49:12 +0000"  >&lt;p&gt;Hi Jeff, &lt;/p&gt;

&lt;p&gt;my first thought is exactly the same as yours, but experiment passed, and this confuses me. Here is the full code that can compile and run: &lt;br/&gt;
		MongoClient mongoClient;&lt;br/&gt;
		MongoDatabase db;&lt;br/&gt;
		mongoClient = new MongoClient(host);&lt;br/&gt;
		db = mongoClient.getDatabase(dbName);&lt;br/&gt;
		FindIterable&amp;lt;Document&amp;gt; it = db.getCollection(&quot;data&quot;).find(queryDoc);&lt;br/&gt;
		it.forEach((Document document) -&amp;gt; System.out.println(document.get(&quot;_id&quot;)));&lt;/p&gt;

&lt;p&gt;My environment: &lt;br/&gt;
    OS: max os 10, JDK: 1.8U66, mongo driver:3.2.1, mongo server: 3.0.4&lt;/p&gt;</comment>
                            <comment id="1147636" author="jeff.yemin" created="Tue, 19 Jan 2016 18:58:29 +0000"  >&lt;p&gt;The first (give doc a type) will not work, as it&apos;s still an ambiguous method call.  But either of the casts will, as that disambiguates the call.&lt;/p&gt;</comment>
                            <comment id="1147165" author="diablox" created="Tue, 19 Jan 2016 13:32:45 +0000"  >&lt;p&gt;I think this breaks the target typing of java lambda expression. &lt;br/&gt;
    ref: &lt;a href=&quot;https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#target-typing&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#target-typing&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I&apos;ve also met this issue and here is what I&apos;ve found after trying around:&lt;br/&gt;
    let &apos;it&apos; be a FindIterable:&lt;br/&gt;
		FindIterable&amp;lt;Document&amp;gt; it = db.getCollection(tableName).find(queryDoc);&lt;br/&gt;
Both of these three ways can work&lt;br/&gt;
    give doc a type:&lt;br/&gt;
		it.forEach((Document doc) -&amp;gt; ret.add(converter.convert(doc)));&lt;br/&gt;
    casting:&lt;br/&gt;
		it.forEach((Block&amp;lt;Document&amp;gt;) doc -&amp;gt; ret.add(converter.convert(doc)));&lt;br/&gt;
		it.forEach((Consumer&amp;lt;Document&amp;gt;) doc -&amp;gt; ret.add(converter.convert(doc)));&lt;/p&gt;

&lt;p&gt;The first one seems using java Iterable&apos;s foreach(not the one from MongoIterable), I&apos;m quite new to lambda, hope someone can explain this behavior. My only guess is java native interfaces comes in a higher priority somehow.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="616635">JAVA-3046</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                                        </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr8u3r:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>