<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 07:45:38 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>[DOCS-3393] Modeling Monetary Data in MongoDB</title>
                <link>https://jira.mongodb.org/browse/DOCS-3393</link>
                <project id="10380" key="DOCS">Documentation</project>
                    <description>&lt;p&gt;The following is something I sent to a user, and resembles something&lt;br/&gt;
we discuss relatively often with users/customers.&lt;/p&gt;

&lt;p&gt;If you feel like documenting this, maybe also see this:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.moschetti.org/rants/mongomoney.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.moschetti.org/rants/mongomoney.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#8211;&lt;br/&gt;
Richard&lt;/p&gt;

&lt;p&gt;&amp;#8211;&lt;br/&gt;
The basic question is how to handle monetary data in MongoDB. There&lt;br/&gt;
are a number of tricky aspects to this problem:&lt;/p&gt;

&lt;p&gt;(A) Many fractional numeric quantities that come up frequently in&lt;br/&gt;
monetary problems have no exact representation in binary floating&lt;br/&gt;
point. For example, one tenth and one third have no exact&lt;br/&gt;
representation in binary floating point.&lt;/p&gt;

&lt;p&gt;(B) Many applications that want to handle monetary data are required&lt;br/&gt;
to conform to some kind of regulatory requirements about how&lt;br/&gt;
arithmetic works on monetary values (e.g., &quot;banker&apos;s rounding&quot; and the&lt;br/&gt;
like). Typically, binary floating point arithmetic (such as the stuff&lt;br/&gt;
implemented in modern hardware, and that MongoDB uses) does not&lt;br/&gt;
conform to applicable regulation for monetary arithmetic.&lt;/p&gt;

&lt;p&gt;MongoDB has no built-in support for storing numeric data except as&lt;br/&gt;
IEEE double-precision (64-bit) floating point numbers, and as 32-bit&lt;br/&gt;
and 64-bit signed integers.&lt;/p&gt;

&lt;p&gt;MongoDB has no built-in support for decimal arithmetic, either exact&lt;br/&gt;
or inexact, except for arithmetic on 32-bit and 64-bit integers.&lt;/p&gt;

&lt;p&gt;So how you handle monetary data in MongoDB depends on the&lt;br/&gt;
use case.&lt;/p&gt;

&lt;p&gt;Broadly speaking, there are two options:&lt;/p&gt;

&lt;p&gt;(1) If you know in advance what the maximum precision for monetary&lt;br/&gt;
data is, and you need to be able to do exact, server-side querying,&lt;br/&gt;
sorting, and incrementing/decrementing: convert the monetary value to&lt;br/&gt;
an integer by scaling by a power of 10 large enough that the smallest&lt;br/&gt;
unit of monetary relevance becomes the least significant digit in the&lt;br/&gt;
integral value. (For example, if you care about things down to the&lt;br/&gt;
tenth of a cent, scale by 1000.)&lt;/p&gt;

&lt;p&gt;This approach allows the application to employ all numerical and&lt;br/&gt;
arithmetic features MongoDB provides, so long as the application&lt;br/&gt;
performs appropriate scaling of operands to these features.&lt;/p&gt;

&lt;p&gt;However, note that every part of the application needs to be&lt;br/&gt;
consistent about this (that&apos;s also true of arithmetic operations in&lt;br/&gt;
systems that use fractional values, however).&lt;/p&gt;

&lt;p&gt;(2) If you need arbitrary or unanticipated precision in your monetary&lt;br/&gt;
data, store two fields: one that encodes the exact value as a&lt;br/&gt;
non-numeric MongoDB data type (BinData or string, say), along with a&lt;br/&gt;
double-precision floating point approxomation of the exact value for&lt;br/&gt;
server-side range and sort queries.&lt;/p&gt;

&lt;p&gt;This way, an application that needs to retrieve or sort data according&lt;br/&gt;
to the monetary value can, if careful, specify suitable range and sort&lt;br/&gt;
specifications to the MongoDB deployment for accessing documents;&lt;br/&gt;
applications that do this will also need to do client-side&lt;br/&gt;
postprocessing (filtering, say) of documents retrieved based on the&lt;br/&gt;
decoding of the opaque representation of the exact value.&lt;/p&gt;

&lt;p&gt;In general this approach is somewhat more restrictive than the&lt;br/&gt;
previous, because the exact value is stored as an additional object&lt;br/&gt;
for which there won&apos;t be any numeric operations available. However, if&lt;br/&gt;
MongoDB is just being used for storage and retrieval, but never update&lt;br/&gt;
or analysis, of monetary data, this approach mostly works.&lt;/p&gt;</description>
                <environment></environment>
        <key id="136110">DOCS-3393</key>
            <summary>Modeling Monetary Data in MongoDB</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="tim.slavin">Tim Slavin</assignee>
                                    <reporter username="tim.slavin">Tim Slavin</reporter>
                        <labels>
                            <label>sprint-rollover</label>
                    </labels>
                <created>Mon, 12 May 2014 20:05:28 +0000</created>
                <updated>Mon, 16 Mar 2015 23:56:10 +0000</updated>
                            <resolved>Tue, 1 Jul 2014 16:29:39 +0000</resolved>
                                                    <fixVersion>v1.3.7</fixVersion>
                                    <component>manual</component>
                        <due></due>
                            <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="658267" author="xgen-internal-githook" created="Mon, 14 Jul 2014 18:05:49 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;TimSlavinMongoDB&apos;, u&apos;name&apos;: u&apos;Tim Slavin (MongoDB)&apos;, u&apos;email&apos;: u&apos;tim.slavin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-3393&quot; title=&quot;Modeling Monetary Data in MongoDB&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-3393&quot;&gt;&lt;del&gt;DOCS-3393&lt;/del&gt;&lt;/a&gt;: Modeling Monetary Data in MongoDB&lt;/p&gt;

&lt;p&gt;Signed-off-by: kay &amp;lt;kay.kim@10gen.com&amp;gt;&lt;br/&gt;
Branch: v2.4&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/47f27ed5f981e38dbfd322140b7881e07680c858&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/47f27ed5f981e38dbfd322140b7881e07680c858&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="654185" author="xgen-internal-githook" created="Wed, 9 Jul 2014 22:59:55 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;TimSlavinMongoDB&apos;, u&apos;name&apos;: u&apos;Tim Slavin (MongoDB)&apos;, u&apos;email&apos;: u&apos;tim.slavin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-3393&quot; title=&quot;Modeling Monetary Data in MongoDB&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-3393&quot;&gt;&lt;del&gt;DOCS-3393&lt;/del&gt;&lt;/a&gt;: Modeling Monetary Data in MongoDB&lt;/p&gt;

&lt;p&gt;Signed-off-by: kay &amp;lt;kay.kim@10gen.com&amp;gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/4a25a90cc2b6d0174e7a35f0be2bdafbeefda3c9&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/4a25a90cc2b6d0174e7a35f0be2bdafbeefda3c9&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="640731" author="samk" created="Tue, 1 Jul 2014 16:29:39 +0000"  >&lt;p&gt;merge still pending&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                    <customfield id="customfield_10855" key="com.atlassian.jira.plugin.system.customfieldtypes:float">
                        <customfieldname>Actual Time</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>8.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 1 Jul 2014 16:29:39 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        9 years, 31 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>jess.mokrzecki@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            9 years, 31 weeks, 2 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>xgen-internal-githook</customfieldvalue>
            <customfieldvalue>sam.kleinman</customfieldvalue>
            <customfieldvalue>tim.slavin</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrr1bj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrys3z:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>117143</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_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hryn5b:</customfieldvalue>

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