<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:57:41 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-2627] Accumulators not working properly</title>
                <link>https://jira.mongodb.org/browse/JAVA-2627</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Accumulators dosn&apos;t work as they should, they just replace the value given instead to process it.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Document document = new Document(&quot;firstname&quot;, &quot;Pedro&quot;)&lt;br/&gt;
	    	      .append(&quot;lastname&quot;, &quot;Doe&quot;) &lt;br/&gt;
	    	      .append(&quot;age&quot;, 14) &lt;br/&gt;
	    	      .append(&quot;country&quot;, &quot;Tanzania&quot;)&lt;br/&gt;
	    	      .append(&quot;index&quot;, 1);&lt;/p&gt;

&lt;p&gt;collection.insertOne(document);&lt;/p&gt;

&lt;p&gt;List&amp;lt;Bson&amp;gt; query= asList(Aggregates.match(Filters.eq(&quot;firstname&quot;, &quot;Pedro&quot;)),Aggregates.group(&quot;$_id&quot;, Accumulators.avg(&quot;age&quot;, 100), Accumulators.sum(&quot;index&quot;, 100)));&lt;br/&gt;
AggregateIterable&amp;lt;Document&amp;gt; resuls t= collection.aggregate(query);&lt;br/&gt;
for(Document d : results)&lt;/p&gt;
{
	 System.out.println(d.toJson());
}

&lt;p&gt;-Result:&lt;br/&gt;
{ &quot;_id&quot; : &lt;/p&gt;
{ &quot;$oid&quot; : &quot;59dbb669dfbc63214831e70c&quot; }
&lt;p&gt;, &quot;age&quot; : 100.0, &quot;index&quot; : 100 }&lt;/p&gt;

&lt;p&gt;-expected:&lt;br/&gt;
{ &quot;_id&quot; : &lt;/p&gt;
{ &quot;$oid&quot; : &quot;59dbb669dfbc63214831e70c&quot; }
&lt;p&gt;, &quot;age&quot; : 57.0, &quot;index&quot; : 101}&lt;/p&gt;</description>
                <environment>Windows 8.1 - IDE Eclipse Java - Java 8 - MongoDB 3.4.9</environment>
        <key id="442694">JAVA-2627</key>
            <summary>Accumulators not working properly</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="13202">Works as Designed</resolution>
                                        <assignee username="ross@mongodb.com">Ross Lawley</assignee>
                                    <reporter username="pendy01">ALESSANDRO PENDINELLI</reporter>
                        <labels>
                            <label>accumulator</label>
                            <label>aggregate</label>
                    </labels>
                <created>Mon, 9 Oct 2017 17:55:12 +0000</created>
                <updated>Fri, 27 Oct 2023 13:21:10 +0000</updated>
                            <resolved>Tue, 10 Oct 2017 08:18:41 +0000</resolved>
                                    <version>3.5.0</version>
                    <version>3.6.0</version>
                                                    <component>BSON</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="1694165" author="ross@10gen.com" created="Tue, 10 Oct 2017 08:18:42 +0000"  >&lt;p&gt;No problems &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=pendy01&quot; class=&quot;user-hover&quot; rel=&quot;pendy01&quot;&gt;pendy01&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;All the best,&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                            <comment id="1693563" author="pendy01" created="Mon, 9 Oct 2017 19:23:45 +0000"  >&lt;p&gt;I&apos;m sorry to posted this as bug now i do understand the proper way to use it.&lt;/p&gt;

&lt;p&gt;Thank you very much for the answer.&lt;/p&gt;</comment>
                            <comment id="1693475" author="ross@10gen.com" created="Mon, 9 Oct 2017 18:30:45 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=pendy01&quot; class=&quot;user-hover&quot; rel=&quot;pendy01&quot;&gt;pendy01&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thanks for the ticket.  I think theres a misunderstanding as to how the the &lt;tt&gt;$avg&lt;/tt&gt; and &lt;tt&gt;$sum&lt;/tt&gt; accumulators work.  Take &lt;tt&gt;Accumulators.age&lt;/tt&gt;:&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;Accumulators.age(fieldName, expression)&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;The &lt;tt&gt;fieldName&lt;/tt&gt;, is the outputted field name - essentially the projected field name.  The &lt;tt&gt;expression&lt;/tt&gt; can relate to a number of different &lt;a href=&quot;https://docs.mongodb.com/manual/meta/aggregation-quick-reference/#agg-quick-ref-expression-objects&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;expressions types&lt;/a&gt;. However, here you probably want to use a field path. &lt;/p&gt;

&lt;p&gt;In the following example, the &lt;tt&gt;age&lt;/tt&gt; field is averaged and projected out into an &lt;tt&gt;averageAge&lt;/tt&gt; field.:&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;Accumulators.avg(&quot;averageAge&quot;,&quot;$age&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;The &lt;tt&gt;sum&lt;/tt&gt; accumulator works in the same fashion.&lt;/p&gt;

&lt;p&gt;I hope that helps,&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                    </comments>
                    <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|ht99vz:</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>