<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:52:12 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-403] UUIDs are stored as little endian (should be big endian)</title>
                <link>https://jira.mongodb.org/browse/JAVA-403</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;In python:&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; import pymongo&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; import uuid&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; from pymongo import Connection&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; c = Connection(&apos;localhost&apos;, 27017)&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; db = c.test&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; db.foo.insert(&lt;/p&gt;
{&quot;python&quot;: uuid.UUID(&quot;aaf4c61d-dcc5-e8a2-dabe-de0f3b482cd9&quot;)}
&lt;p&gt;)&lt;br/&gt;
ObjectId(&apos;4e318fb98f1e81eac4000001&apos;)&lt;/p&gt;

&lt;p&gt;In java:&lt;br/&gt;
		UUID id = UUID.fromString(&quot;aaf4c61d-dcc5-e8a2-dabe-de0f3b482cd9&quot;);&lt;br/&gt;
		Mongo mongo = new Mongo();&lt;br/&gt;
		DB db = mongo.getDB(&quot;test&quot;);&lt;br/&gt;
		DBObject dbo = new BasicDBObject();&lt;br/&gt;
		dbo.put(&quot;java&quot;, id);&lt;br/&gt;
		db.getCollection(&quot;foo&quot;).insert(dbo);&lt;/p&gt;

&lt;p&gt;Result:&lt;br/&gt;
&amp;gt; db.foo.find()&lt;/p&gt;
{ &quot;_id&quot; : ObjectId(&quot;4e318fb98f1e81eac4000001&quot;), &quot;python&quot; : UUID(&apos;aaf4c61ddcc5e8a2dabede0f3b482cd9&apos;) }
{ &quot;_id&quot; : ObjectId(&quot;4e318fc12746ac3aa375aee9&quot;), &quot;java&quot; : UUID(&apos;a2e8c5dc1dc6f4aad92c483b0fdebeda&apos;) }

&lt;p&gt;(yes, with the patch from &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1201&quot; title=&quot;shell support for UUID (binary subtype 3)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1201&quot;&gt;&lt;del&gt;SERVER-1201&lt;/del&gt;&lt;/a&gt; applied)&lt;/p&gt;

&lt;p&gt;Java seems to serialize/deserialize the UUIDs as little endian according to BSONEncoder.java, line 354&lt;/p&gt;

&lt;p&gt;Changing this would however break a lot of applications out there. However, the python/java incompatibility is really bad, so it should be fixed in my humble opinion...&lt;/p&gt;</description>
                <environment>MacOS X 10.6 (which implies a little endian x86/64 CPU)</environment>
        <key id="20248">JAVA-403</key>
            <summary>UUIDs are stored as little endian (should be big endian)</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="robert.guo@mongodb.com">Robert Guo</assignee>
                                    <reporter username="vboivie">Victor Boivie</reporter>
                        <labels>
                            <label>SERVER_V2</label>
                            <label>uuid</label>
                    </labels>
                <created>Thu, 28 Jul 2011 16:41:01 +0000</created>
                <updated>Wed, 1 May 2019 18:49:52 +0000</updated>
                            <resolved>Thu, 9 Oct 2014 13:46:29 +0000</resolved>
                                                    <fixVersion>3.0.0</fixVersion>
                                    <component>Codecs</component>
                    <component>Configuration</component>
                                        <votes>7</votes>
                                    <watches>13</watches>
                                                                                                                <comments>
                            <comment id="869393" author="jeff.yemin" created="Tue, 31 Mar 2015 20:09:41 +0000"  >&lt;p&gt;Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.&lt;/p&gt;</comment>
                            <comment id="817943" author="xgen-internal-githook" created="Fri, 30 Jan 2015 18:43:36 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;guoyr&apos;, u&apos;name&apos;: u&apos;Robert Guo&apos;, u&apos;email&apos;: u&apos;robert.guo@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-403&quot; title=&quot;UUIDs are stored as little endian (should be big endian)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-403&quot;&gt;&lt;del&gt;JAVA-403&lt;/del&gt;&lt;/a&gt; allow user to specify UUID format&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/3d44a7e300f5359690d1b5870c7509f3617552f2&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/3d44a7e300f5359690d1b5870c7509f3617552f2&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="737467" author="xgen-internal-githook" created="Thu, 9 Oct 2014 13:45:53 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;guoyr&apos;, u&apos;name&apos;: u&apos;Robert Guo&apos;, u&apos;email&apos;: u&apos;robert.guo@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-403&quot; title=&quot;UUIDs are stored as little endian (should be big endian)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-403&quot;&gt;&lt;del&gt;JAVA-403&lt;/del&gt;&lt;/a&gt; allow user to specify UUID format&lt;br/&gt;
Branch: 3.0.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/3d44a7e300f5359690d1b5870c7509f3617552f2&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/3d44a7e300f5359690d1b5870c7509f3617552f2&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="238057" author="jeff.yemin" created="Sat, 12 Jan 2013 13:10:46 +0000"  >&lt;p&gt;Moving to 3.0 release, unfortunately.  The only way to do this in 2.x is with the DBEncoder/DBDecoder framework, and we&apos;re likely going to be getting rid of that framework in 3.0. &lt;/p&gt;</comment>
                            <comment id="224830" author="behackett" created="Wed, 26 Dec 2012 22:11:28 +0000"  >&lt;p&gt;Philipp, you can already do this in PyMongo:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.uuid_subtype&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.uuid_subtype&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Valid settings are OLD_UUID_SUBTYPE (3 - the current default), UUID_SUBTYPE (4 - will be the default in some future release), JAVA_LEGACY, and CSHARP_LEGACY.&lt;/p&gt;

&lt;p&gt;This is a per-collection setting so that you can use subtype 4 in new collections but use legacy byte orders in existing collections.&lt;/p&gt;</comment>
                            <comment id="224815" author="scp" created="Wed, 26 Dec 2012 22:01:41 +0000"  >&lt;p&gt;@Nils&lt;br/&gt;
For our case we needed Subtype 3 because Python was/is using the same database. We did not needed backward compatibility because the database was empty.&lt;br/&gt;
Python and Java needed to read and write the same database.&lt;br/&gt;
Our patch is not a general fix for this issue. It is a quick and working solution which only works if you start with an empty database and do not care about backward compatibility.&lt;/p&gt;

&lt;p&gt;From a mongodb user point, it would be nice if the final fix/solution would have an option where the user of the driver can define if he wants to use subtype4 or subtype3 (3 will have no backward compatibility). On option in some kind of settings would be nice.&lt;/p&gt;</comment>
                            <comment id="219267" author="nilskp" created="Wed, 19 Dec 2012 14:23:52 +0000"  >&lt;p&gt;The fix appears to still use subtype 3, which will break backwards compatibility. Any reason not to switch to subtype 4, which arguably is is the correct subtype, while retaining backwards compatibility?&lt;/p&gt;</comment>
                            <comment id="189301" author="scp" created="Wed, 14 Nov 2012 16:54:27 +0000"  >&lt;p&gt;Hello,&lt;br/&gt;
we have patched the driver and using the patched version since a few month. We have just upgraded to the newest driver version.&lt;br/&gt;
You can download the patched version here:&lt;br/&gt;
&lt;a href=&quot;https://github.com/mila-labs/mongo-java-driver/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mila-labs/mongo-java-driver/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use at own risk and only if you have NO DATA yet in the database&lt;/p&gt;</comment>
                            <comment id="180599" author="jeff.yemin" created="Tue, 30 Oct 2012 17:07:28 +0000"  >&lt;p&gt;Nils, we&apos;re working on a way to do this without breaking compatibility.  Should know more in a week or so.&lt;/p&gt;</comment>
                            <comment id="178708" author="nilskp" created="Wed, 24 Oct 2012 15:52:14 +0000"  >&lt;p&gt;According to the BSON spec, binary subtype 4 is standard UUID, and 3 is legacy, so there should be no problem implementing subtype 4 encoding, while falling back to properly decoding old subtype 3 legacy.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://bsonspec.org/#/specification&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://bsonspec.org/#/specification&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="178685" author="nilskp" created="Wed, 24 Oct 2012 15:15:21 +0000"  >&lt;p&gt;Can we at the very least get something like a static global switch to fix this issue for those of us who do not have legacy issues and would like to not start creating legacy issues? The fix should be simple enough and be backwards compatible.&lt;/p&gt;</comment>
                            <comment id="178676" author="nilskp" created="Wed, 24 Oct 2012 15:03:43 +0000"  >&lt;p&gt;I&apos;ve just been hit with this problem. Unable to get consistent view of data in Java and everything else. And apparently no pending fix. I don&apos;t understand how this is not a higher priority. The UUID, as seen from Java, does not match what the shell or any other tool is seeing. It makes it almost impossible to work with the data.&lt;/p&gt;</comment>
                            <comment id="81982" author="mitsuhiko" created="Tue, 24 Jan 2012 16:11:33 +0000"  >&lt;p&gt;The official BSON specification does not list Binary subtype 4 at all at the moment but some drivers have already started to accept it (for instance the Python one) and MongoDB itself also already handles binary subtype 4.  May I suggest adding at the very least a note to the binary specification and adding a link to this issue or related ones?&lt;/p&gt;</comment>
                            <comment id="63732" author="mark1ewis" created="Mon, 31 Oct 2011 16:55:44 +0000"  >&lt;p&gt;A graph showing insertion speed of an object with a UUID value as its _id.  For this issue, the difference between Timestamp UUID and Timestamp (order swap) is the important bit.&lt;/p&gt;</comment>
                            <comment id="63714" author="mark1ewis" created="Mon, 31 Oct 2011 16:11:17 +0000"  >&lt;p&gt;I recently performed some benchmarking of Mongo insert performance where a UUID field is indexed.  The current (wrong) implementation performed about 50% slower than a corrected UUID implementation for timestamp-based UUIDs, because timestamp-based UUIDs are supposed to have the same mostly-increasing behavior as ObjectId, but due to this issue they are not.  So there is a performance aspect to this issue as well.&lt;/p&gt;</comment>
                            <comment id="58249" author="rstam" created="Mon, 3 Oct 2011 19:50:19 +0000"  >&lt;p&gt;Maybe not, because the binary subtype would be different (3 for legacy representations and 4 for the new standard representation).&lt;/p&gt;</comment>
                            <comment id="58239" author="jeff.yemin@mtvstaff.com" created="Mon, 3 Oct 2011 18:14:14 +0000"  >&lt;p&gt;Isn&apos;t it the case that $in may produce false positives?&lt;/p&gt;</comment>
                            <comment id="45362" author="antoine" created="Fri, 29 Jul 2011 21:05:16 +0000"  >&lt;p&gt;this is the plan.&lt;br/&gt;
The only issue is when you want to find a doc by its UUID, you wont be sure which one it&apos;s stored under, so you will have to try both in your app (I guess an $in op will be clean enough).&lt;br/&gt;
Also if you do sorting on that field it will not be consistent (hopefully not a problem in most cases).&lt;br/&gt;
We can&apos;t do tricks on the db side because other drivers were storing UUID correctly.&lt;br/&gt;
AG&lt;/p&gt;</comment>
                            <comment id="45343" author="vboivie" created="Fri, 29 Jul 2011 19:28:57 +0000"  >&lt;p&gt;&amp;gt;Also, keeping the type as a binary subtypes makes it easer and more like the current impl.&lt;/p&gt;

&lt;p&gt;Understandable.&lt;/p&gt;

&lt;p&gt;&amp;gt;the old one will be read as new class (UUIDJava/Legacy probably)&lt;/p&gt;

&lt;p&gt;Can&apos;t you do it like this: (we here assume that the new binary subtype for &apos;new-style UUID&apos; is 6)&lt;/p&gt;

&lt;p&gt;dbo.put(&quot;foo&quot;, new java.util.UUID(1,2)) -&amp;gt; save as subtype 6&lt;br/&gt;
dbo.get(&quot;foo&quot;) and stored as subtype 6 -&amp;gt; return java.util.UUID class&lt;br/&gt;
dbo.put(&quot;foo&quot;, new org.bson.LegacyUUID(1,2)) -&amp;gt; save as subtype 3&lt;br/&gt;
dbo.get(&quot;foo&quot;) and stored as subtype 3 -&amp;gt; return java.util.UUID class, but deserialized using the old style&lt;/p&gt;

&lt;p&gt;That way, old code will work (and will automatically convert to the new format as the documents are updated). And we could still use the defacto java.lang.UUID class and not care about the legacy type provided that we don&apos;t care how the documents are stored in the DB&lt;/p&gt;</comment>
                            <comment id="45092" author="scotthernandez" created="Thu, 28 Jul 2011 17:05:38 +0000"  >&lt;p&gt;It would be great to be able to subclass UUID but it is final unfortunately. We will make UUID be stored as the new subtype and the old one will be read as new class (UUIDJava/Legacy probably). The rest of the details are yet to finished. You will be able to store/retrieve either type, but new UUIDs will be stored as the new, and compatible, bson type.&lt;/p&gt;

&lt;p&gt;Also, keeping the type as a binary subtypes makes it easer and more like the current impl.&lt;/p&gt;</comment>
                            <comment id="45088" author="vboivie" created="Thu, 28 Jul 2011 16:49:25 +0000"  >&lt;p&gt;It could even be a top level BSON type (and not a binary type), which could save 5 additional bytes per entry as the length is always the same.&lt;/p&gt;

&lt;p&gt;How would that be activated? By setting an option to the driver somehow? Because I really hope that you will still use the languages&apos; own native UUID classes as it is today. And not reinvent a new one in the BSON namespace.&lt;/p&gt;</comment>
                            <comment id="45086" author="scotthernandez" created="Thu, 28 Jul 2011 16:45:52 +0000"  >&lt;p&gt;Yes, there is a plan to deprecate the current UUID binary subtype and create a new one which is binary compatible for all drivers. It will be a breaking change but one that the developers can choose to implement by migrating data, or having handler code in the app.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                                                <inwardlinks description="is depended on by">
                                                        </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                                        </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="76697">DOCS-1543</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="46611">PYTHON-387</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="13668" name="GUID-Insertion-Speed.png" size="58886" author="mark1ewis" created="Mon, 31 Oct 2011 16:55:43 +0000"/>
                    </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|hrf53z:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>909</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="264">Java Sprint 7</customfieldvalue>
    <customfieldvalue id="265">Java Sprint 8</customfieldvalue>
    <customfieldvalue id="298">Java Sprint 9</customfieldvalue>

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