<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:55:49 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-1905] Bson instances returned from Filters, Updates, and Aggregates methods should implement equals() or hashCode()</title>
                <link>https://jira.mongodb.org/browse/JAVA-1905</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Filter implementations in com.mongodb.client.model.Filters from the 3.0.X Java driver do not implement the equals() method.  This is causing great difficulty unit testing the data layer since you can&apos;t compare a Filter Bson object with an expected value.&lt;/p&gt;</description>
                <environment></environment>
        <key id="222779">JAVA-1905</key>
            <summary>Bson instances returned from Filters, Updates, and Aggregates methods should implement equals() or hashCode()</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="john.stewart@mongodb.com">John Stewart</assignee>
                                    <reporter username="blake_bauman@apple.com">Blake Bauman</reporter>
                        <labels>
                    </labels>
                <created>Mon, 27 Jul 2015 06:04:54 +0000</created>
                <updated>Sun, 16 Jun 2019 21:40:49 +0000</updated>
                            <resolved>Fri, 8 Feb 2019 15:39:41 +0000</resolved>
                                    <version>3.0.2</version>
                                    <fixVersion>3.11.0</fixVersion>
                                    <component>Builders</component>
                                        <votes>4</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="2142483" author="xgen-internal-githook" created="Fri, 8 Feb 2019 15:39:18 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;John Stewart&apos;, &apos;email&apos;: &apos;john.stewart@mongodb.com&apos;, &apos;username&apos;: &apos;jstewart-mongo&apos;}
&lt;p&gt;Message: Implement equals and hashCode methods for Bson instances&lt;br/&gt;
returned from Filters, Aggregates, Indexes, Sorts and Updates&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-1905&quot; title=&quot;Bson instances returned from Filters, Updates, and Aggregates methods should implement equals() or hashCode()&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-1905&quot;&gt;&lt;del&gt;JAVA-1905&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/fc8b272e144265d736036c52902479a9b86e2053&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/fc8b272e144265d736036c52902479a9b86e2053&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1732713" author="pwojnowski" created="Wed, 22 Nov 2017 11:02:44 +0000"  >&lt;p&gt;This is really annoying issue. One needs to use Document(...) instead, because it can be compared in unit tests.&lt;/p&gt;</comment>
                            <comment id="1246094" author="blake_bauman@apple.com" created="Mon, 25 Apr 2016 22:06:13 +0000"  >&lt;p&gt;Currently, to get around this issue, we&apos;re using Mockito with ArgumentCaptor objects.  We capture the arg, then take the expected Bson and the actual Bson, convert both to JSON strings using a codec registry (since toString() doesn&apos;t work,either), then compare the resulting strings to validate.&lt;/p&gt;

&lt;p&gt;It ends up being quite a big pain to do this for all the tests.&lt;/p&gt;</comment>
                            <comment id="1245926" author="jeff.yemin" created="Mon, 25 Apr 2016 20:18:34 +0000"  >&lt;p&gt;Added Updates and Aggregates to this issue, in addition to Filters.&lt;/p&gt;</comment>
                            <comment id="989845" author="blake_bauman@apple.com" created="Mon, 27 Jul 2015 17:53:42 +0000"  >&lt;p&gt;While that&apos;s technically true, all of the collections in java.util.Collections would have the same problem.  All it would need to guarantee is that equals() returns true for its values.&lt;/p&gt;

&lt;p&gt;The problem is, we&apos;re not trying to call assertEquals() on the Bson document, we&apos;re using mock objects.  The mock object frameworks rely on equals() to know when a particular method has been invoked with specific arguments.  Something like:&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;    final Bson bson = Filters.eq(&quot;a&quot;, &quot;b&quot;);&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;    when(myMock.someMethod(bson)).thenReturn(&quot;foo&quot;);&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;    verify(myMock).someMethod(bson);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</comment>
                            <comment id="989458" author="jeff.yemin" created="Mon, 27 Jul 2015 13:00:07 +0000"  >&lt;p&gt;There is no way to properly implement equals directly on the Bson instances returned from the Filters factory methods because there is no way to ensure that all the values contained in the filter itself implement equals.   But there is an easy workaround: since BsonDocument implements equals, and the Bson interface has a toBsonDocument method, you can do something like this:&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;     CodecRegistry codecRegistry = ...&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;     Bson filter = Filters.eq(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;field&quot;&lt;/span&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;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;     assertEquals(BsonDocument.parse(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;{&quot;&lt;/span&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;field : ...}&quot;), filter.toBsonDocument(Document.&lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;class&lt;/span&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;, codeRegistry));&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;This is exactly how we &lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/test/unit/com/mongodb/client/model/FiltersSpecification.groovy&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;test&lt;/a&gt; the correctness of the Filters class itself.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="259440">JAVA-2092</issuekey>
        </issuelink>
                            </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|hr7m8v:</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>