<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:17 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>[CSHARP-597] Using .NET Guid as mongodb document id</title>
                <link>https://jira.mongodb.org/browse/CSHARP-597</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I&apos;m trying to use .NET Guid as document id for my mongodb documents. The problem that I face now is that I can&apos;t fetch new document by id after insertion:&lt;/p&gt;

&lt;p&gt;MongoCollection.AsQueryable().Where(user =&amp;gt; user.Id == id)&lt;/p&gt;

&lt;p&gt;I saw that Guid bytes are reversed in MongoDb, so I tried something like this:&lt;/p&gt;

&lt;p&gt;public TData GetById(Guid id)&lt;/p&gt;
		{
		    var reverseId = Reverse(id);
            return MongoCollection.AsQueryable()
                .Where(user =&amp;gt; user.Id == reverseId) as TData;
		}

&lt;p&gt;        private static Guid Reverse(Guid initial)&lt;/p&gt;
        {
            byte[] guidBytes = initial.ToByteArray();
            Array.Reverse(guidBytes, 0, 4);
            Array.Reverse(guidBytes, 4, 2);
            Array.Reverse(guidBytes, 6, 2);
            return new Guid(guidBytes);
        }
&lt;p&gt;Still, it does not work... Please help.&lt;/p&gt;</description>
                <environment></environment>
        <key id="52769">CSHARP-597</key>
            <summary>Using .NET Guid as mongodb document id</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="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="nsushkov">Nikita Sushkov</reporter>
                        <labels>
                    </labels>
                <created>Wed, 10 Oct 2012 11:46:07 +0000</created>
                <updated>Thu, 20 Mar 2014 14:35:46 +0000</updated>
                            <resolved>Wed, 10 Oct 2012 14:00:07 +0000</resolved>
                                    <version>1.6</version>
                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="173304" author="craiggwilson" created="Wed, 10 Oct 2012 14:00:07 +0000"  >&lt;p&gt;Ok, then I&apos;m going to close this issue.&lt;/p&gt;</comment>
                            <comment id="173303" author="nsushkov" created="Wed, 10 Oct 2012 13:57:12 +0000"  >&lt;p&gt;Thanks for answer, actually whong query syntax was the real problem, but when I saw reverted bytes in mongodb I thought that was the reason...&lt;/p&gt;</comment>
                            <comment id="173301" author="craiggwilson" created="Wed, 10 Oct 2012 13:40:55 +0000"  >&lt;p&gt;Are you still doing the byte reversals?  That should not be necessary under any circumstances.&lt;/p&gt;

&lt;p&gt;.Where should work just fine, but it returns all the documents that match, which in this case would only be one, so you&apos;d need to iterate to get the first doc.  In this case, SingleOrDefault makes more sense, but you should never have to do any byte reversing at all.&lt;/p&gt;</comment>
                            <comment id="173285" author="nsushkov" created="Wed, 10 Oct 2012 12:41:37 +0000"  >&lt;p&gt;Was my mistake. Query should look like this:&lt;/p&gt;

&lt;p&gt;_collection.AsQueryable().SingleOrDefault(user =&amp;gt; user.Id == id)&lt;/p&gt;

&lt;p&gt;Works fine.&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|hrjx3z:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>29901</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>