<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 05:22:56 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>[SERVER-50541] Problem when the $trunc operator</title>
                <link>https://jira.mongodb.org/browse/SERVER-50541</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/274889/274889_image-2020-08-20-17-35-41-798.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;I have a problem when I truncate a number that has the same decimals that have the&#160; &amp;lt;place&amp;gt; value. the problem is that the value is round to down and give the wrong number. I have the following situation:&lt;br/&gt;
a number: 4.56 in my DB and the following query: { $project: { newField: { $trunc: &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;$number&amp;quot;, 2&amp;#93;&lt;/span&gt; }} }&lt;br/&gt;
the outcome of this query is 4.55 a wrong value, I was expecting to get the same number that I stored before. The documentation says the following:&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/274891/274891_image-2020-08-20-17-33-08-167.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Because of that, I don&apos;t understand the reason for the error and also the documentation doesn&apos;t show an example when the &amp;lt;place&amp;gt; and the &amp;lt;number&amp;gt; has the same digits.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Image reference:&lt;/p&gt;

&lt;p&gt;Data on the DB&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/274888/274888_image-2020-08-20-17-38-05-874.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Output, after apply the query&#160;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/274887/274887_image-2020-08-20-17-39-09-282.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</description>
                <environment></environment>
        <key id="1448300">SERVER-50541</key>
            <summary>Problem when the $trunc operator</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="backlog-query-execution">Backlog - Query Execution</assignee>
                                    <reporter username="evercabarcasmallarino@gmail.com">Ever N/A</reporter>
                        <labels>
                            <label>Operator</label>
                            <label>bug</label>
                            <label>mongodb</label>
                            <label>qexec-team</label>
                    </labels>
                <created>Thu, 20 Aug 2020 22:40:49 +0000</created>
                <updated>Fri, 27 Oct 2023 13:52:42 +0000</updated>
                            <resolved>Mon, 9 Jan 2023 15:10:16 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="5099820" author="JIRAUSER1270969" created="Mon, 9 Jan 2023 15:09:56 +0000"  >&lt;p&gt;I left a detailed comment about floating point numbers in a similar ticket: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-71557&quot; title=&quot;The server does not always round half to even&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-71557&quot;&gt;&lt;del&gt;SERVER-71557&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Summary: internally floating point numbers represented in binary (as is everything in computers). When converting to binary, 4.56 is actually an infinite number: 4.56(10) = 100.1000 1111 0101 1100 0010 1000 1111 0101 1100 0010 1000 1111 0101 1&lt;/p&gt;

&lt;p&gt;In 64-bit double precision floating point format it is stored approximately.&lt;br/&gt;
You can see this if you print it with fixed number of decimal digits:&lt;/p&gt;

&lt;p&gt;JavaScript/MongoDB shell:&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: #009900; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;4.56&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;.toFixed(&lt;/span&gt;&lt;span style=&quot;color: #009900; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;20&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: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&apos;4.55999999999999960920&apos;&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;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;So when you call {$trunc: &lt;span class=&quot;error&quot;&gt;&amp;#91;4.56, 2&amp;#93;&lt;/span&gt;}, it is correctly truncated to 4.55.&lt;/p&gt;

&lt;p&gt;This is not something unique to MongoDB, it is a part of IEEE-754 standard, used commonly across databases and programming languages.&lt;/p&gt;

&lt;p&gt;If you want more precision, you can try using Decimal128 data type.&lt;/p&gt;

&lt;p&gt;We created a ticket to improve the documentation around this to avoid confusion around such issues.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="3426856" author="evercabarcasmallarino@gmail.com" created="Mon, 5 Oct 2020 22:40:27 +0000"  >&lt;p&gt;Hey Eric don&apos;t worry for the delay, about the NumberDecimal type I don&apos;t do test with it but you have reason about the exact precision. The thing that I don&apos;t understand is the behavior when we do the operation and it has a specific number of decimal places this behavior is good?&lt;/p&gt;</comment>
                            <comment id="3426805" author="eric.sedor" created="Mon, 5 Oct 2020 22:13:21 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=evercabarcasmallarino%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;evercabarcasmallarino@gmail.com&quot;&gt;evercabarcasmallarino@gmail.com&lt;/a&gt;, and sorry for the delay. I am passing this on to an appropriate team.&lt;/p&gt;

&lt;p&gt;It&apos;s worth noting that the &lt;a href=&quot;https://docs.mongodb.com/manual/core/shell-types/#numberdecimal&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;NumberDecimal&lt;/a&gt; type in the MongoDB shell (or Decimal128 in Compass), is intended for &quot;exact precision when rounding&quot; (and probably truncing). The behavior you describe doesn&apos;t seem to occur for that type.&lt;/p&gt;</comment>
                            <comment id="3359688" author="massimiliano.marcon" created="Wed, 26 Aug 2020 06:59:36 +0000"  >&lt;p&gt;Not a compass or shell issue.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10420">
                    <name>Backports</name>
                                            <outwardlinks description="backported by">
                                                        </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="2192511">SERVER-71557</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="274892" name="image-2020-08-20-17-32-19-994.png" size="14084" author="evercabarcasmallarino@gmail.com" created="Thu, 20 Aug 2020 22:32:24 +0000"/>
                            <attachment id="274891" name="image-2020-08-20-17-33-08-167.png" size="14084" author="evercabarcasmallarino@gmail.com" created="Thu, 20 Aug 2020 22:33:12 +0000"/>
                            <attachment id="274890" name="image-2020-08-20-17-35-17-122.png" size="7745" author="evercabarcasmallarino@gmail.com" created="Thu, 20 Aug 2020 22:35:21 +0000"/>
                            <attachment id="274889" name="image-2020-08-20-17-35-41-798.png" size="7745" author="evercabarcasmallarino@gmail.com" created="Thu, 20 Aug 2020 22:35:45 +0000"/>
                            <attachment id="274888" name="image-2020-08-20-17-38-05-874.png" size="29196" author="evercabarcasmallarino@gmail.com" created="Thu, 20 Aug 2020 22:38:10 +0000"/>
                            <attachment id="274887" name="image-2020-08-20-17-39-09-282.png" size="27777" author="evercabarcasmallarino@gmail.com" created="Thu, 20 Aug 2020 22:39:13 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18555" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname># of Sprints</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9.0</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_12751" key="com.atlassian.jira.plugin.system.customfieldtypes:multiselect">
                        <customfieldname>Assigned Teams</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="25125"><![CDATA[Query Execution]]></customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12450" key="com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes">
                        <customfieldname>Backport Requested</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="18953"><![CDATA[v4.4]]></customfieldvalue>
    <customfieldvalue key="16775"><![CDATA[v4.2]]></customfieldvalue>
    <customfieldvalue key="15640"><![CDATA[v4.0]]></customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Wed, 26 Aug 2020 06:59:36 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        1 year, 4 weeks, 2 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>luke.bonanomi@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            1 year, 4 weeks, 2 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>backlog-query-execution</customfieldvalue>
            <customfieldvalue>eric.sedor@mongodb.com</customfieldvalue>
            <customfieldvalue>evercabarcasmallarino@gmail.com</customfieldvalue>
            <customfieldvalue>ivan.fefer@mongodb.com</customfieldvalue>
            <customfieldvalue>massimiliano.marcon@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hy1frj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr2io7:</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>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="4459">Query 2021-01-11</customfieldvalue>
    <customfieldvalue id="4472">Query Execution 2021-05-03</customfieldvalue>
    <customfieldvalue id="4697">Query Execution 2021-05-17</customfieldvalue>
    <customfieldvalue id="5267">QE 2021-10-18</customfieldvalue>
    <customfieldvalue id="5269">QE 2021-11-01</customfieldvalue>
    <customfieldvalue id="5271">QE 2021-11-15</customfieldvalue>
    <customfieldvalue id="5273">QE 2021-11-29</customfieldvalue>
    <customfieldvalue id="5275">QE 2021-12-13</customfieldvalue>
    <customfieldvalue id="5277">QE 2021-12-27</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                    <customfieldvalue><![CDATA[eric.sedor@mongodb.com]]></customfieldvalue>
    

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hy120v:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>