<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:35:07 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>[GODRIVER-860] Document using UUIDs in mongo as _id&apos;s.</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-860</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;I&apos;ve been told that there&apos;s already support for using mongo&apos;s UUID as an _id, but I can&apos;t figure out how to do it, and I&apos;ve not been able to find any documentation on it.&#160; If there&apos;s a way to do it, can we please detail it in the README for mongo-go-driver?&lt;/p&gt;</description>
                <environment></environment>
        <key id="709053">GODRIVER-860</key>
            <summary>Document using UUIDs in mongo as _id&apos;s.</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</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="9">Done</resolution>
                                        <assignee username="benji.rewis@mongodb.com">Benji Rewis</assignee>
                                    <reporter username="slooker">Shawn Looker</reporter>
                        <labels>
                    </labels>
                <created>Mon, 4 Mar 2019 20:24:43 +0000</created>
                <updated>Mon, 8 Aug 2022 18:00:47 +0000</updated>
                            <resolved>Mon, 8 Aug 2022 17:58:37 +0000</resolved>
                                                                    <component>Documentation</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="4735504" author="benji.rewis" created="Mon, 8 Aug 2022 17:58:37 +0000"  >&lt;p&gt;Feel free to follow up on this ticket if you have further questions or on &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-2484&quot; title=&quot;Add a Go type for the UUID BSON binary subtype&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-2484&quot;&gt;GODRIVER-2484&lt;/a&gt; if you&apos;re curious about the new UUID type!&#160;I&apos;ve added a comment to &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-2484&quot; title=&quot;Add a Go type for the UUID BSON binary subtype&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-2484&quot;&gt;GODRIVER-2484&lt;/a&gt; to make sure we document the new type&apos;s usage alongside &lt;tt&gt;primitive.ObjectID&lt;/tt&gt;.&lt;/p&gt;</comment>
                            <comment id="4735501" author="benji.rewis" created="Mon, 8 Aug 2022 17:57:57 +0000"  >&lt;p&gt;Hello again &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=slooker&quot; class=&quot;user-hover&quot; rel=&quot;slooker&quot;&gt;slooker&lt;/a&gt;&#160;! Just wanted to follow up on this ticket with a bit more information; apologies for the rather extreme delay haha.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;I&apos;ve been told that there&apos;s already support for using mongo&apos;s UUID as an _id&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;MongoDB uses &quot;object IDs&quot; as the type for fields like &quot;&lt;em&gt;id&quot;. While the creation of object IDs and UUIDs differ, their use-case is basically the same (to &quot;uniquely&quot; represent an object). Internally, the Go driver will automatically generate a &lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/blob/master/bson/primitive/objectid.go#L29&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;&lt;tt&gt;primitive.ObjectID&lt;/tt&gt;&lt;/a&gt; for the &lt;tt&gt;_id&lt;/tt&gt; field if the &lt;tt&gt;_id&lt;/tt&gt; field is not provided. &lt;tt&gt;primitive.ObjectID&lt;/tt&gt; is encoded as BSON type 0x07. There _is&lt;/em&gt; support for object IDs with &lt;tt&gt;primitive.ObjectID&lt;/tt&gt;. If your &lt;tt&gt;assetID&lt;/tt&gt; is just being used to represent the Mongo document&apos;s ID, &lt;tt&gt;SomeStruct&lt;/tt&gt; could just have an &lt;tt&gt;id&lt;/tt&gt; field of type &lt;tt&gt;primitive.ObjectID&lt;/tt&gt; (with a struct tag &lt;tt&gt;bson:&quot;_id&quot;&lt;/tt&gt;).&lt;/p&gt;

&lt;p&gt;If, however, &lt;tt&gt;assetID&lt;/tt&gt; is a UUID type like &lt;tt&gt;google.UUID&lt;/tt&gt; that is generated somewhere else in your application, it may be more difficult to use with MongoDB and the Go driver. Encoding and decoding of external UUID types is generally done with 0x05 (BSON binary type) or 0x00 (generic binary). There is currently no type in the Go driver to represent UUIDs but we&apos;re planning to add one with &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-2484&quot; title=&quot;Add a Go type for the UUID BSON binary subtype&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-2484&quot;&gt;GODRIVER-2484&lt;/a&gt;.&lt;/p&gt;</comment>
                            <comment id="2169936" author="slooker" created="Mon, 4 Mar 2019 20:29:55 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=kris.brandow&quot; class=&quot;user-hover&quot; rel=&quot;kris.brandow&quot;&gt;kris.brandow&lt;/a&gt; said you can do it like this:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;You should be able to check the type of the&#160;&lt;tt&gt;_id&lt;/tt&gt;&#160;field, if it&apos;s 0x05 then it&apos;s a BSON Binary type (so UUID) and if it&apos;s 0x07 it&apos;s a BSON ObjectID.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;But if I&apos;m querying like this, I have no idea how you would use a UUID to query,&#160; or what sort of field you&apos;d need to define in your struct for the _id field&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;tt&gt;var result SomeStruct&lt;/tt&gt;{}&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;err = client.Database(databaseName).Collection(collection).FindOne(ctx, bson.M{&quot;_id&quot;: assetID}).Decode(&amp;amp;result)&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="2084083">GODRIVER-2484</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </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|hr6k64:ui</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>