<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:35:44 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-77] MongoCollection.Save() Upserts a random document if it cannot match the ID.</title>
                <link>https://jira.mongodb.org/browse/CSHARP-77</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I have a class:&lt;/p&gt;


&lt;p&gt;    public class Foo&lt;br/&gt;
    {&lt;/p&gt;



&lt;p&gt;        public ObjectId _id &lt;/p&gt;
{ get; set; }&lt;br/&gt;
&lt;br/&gt;
        public string Name { get; set; }

&lt;p&gt;        public string Summary &lt;/p&gt;
{ get; set; }
&lt;p&gt;    }&lt;/p&gt;

&lt;p&gt;And I have a function for inserting it&lt;/p&gt;

&lt;p&gt;        public void EditFoo(Foo fooBar)&lt;/p&gt;
        {
            _db[&quot;fooBar&quot;].Save(fooBar, SafeMode.True);
        }

&lt;p&gt;If fooBar._id exists in the database the save function does an update. If fooBar.Id does not exist it seems as if the driver is picking a document in the collection. and replacing it with my content.&lt;/p&gt;</description>
                <environment></environment>
        <key id="13451">CSHARP-77</key>
            <summary>MongoCollection.Save() Upserts a random document if it cannot match the 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="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="zippy1981">Justin Dearing</reporter>
                        <labels>
                    </labels>
                <created>Fri, 22 Oct 2010 00:40:06 +0000</created>
                <updated>Wed, 19 Oct 2016 14:16:07 +0000</updated>
                            <resolved>Fri, 22 Oct 2010 06:23:42 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="19476" author="rstam" created="Fri, 22 Oct 2010 06:23:42 +0000"  >&lt;p&gt;Fixed. Was a complicated combination of not properly detecting which property of the class should be the Id and then not properly handling Save or Insert of a document that has no Id. So there were actually several related bugs. Part of the solution involved adding these new methods to IBsonSerializer:&lt;/p&gt;

&lt;p&gt;        bool DocumentHasIdProperty(object document);&lt;br/&gt;
        bool DocumentHasIdValue(object document, out object existingId);&lt;br/&gt;
        void GenerateDocumentId(object document);&lt;/p&gt;

&lt;p&gt;and adding a new IBsonIdGenerator interface with these methods:&lt;/p&gt;

&lt;p&gt;        object GenerateId();&lt;br/&gt;
        bool IsEmpty(object id);&lt;/p&gt;

&lt;p&gt;The first operate at the document level and handle:&lt;/p&gt;

&lt;p&gt;1. Determining whether the document has an Id property&lt;br/&gt;
2. Determining whether the Id property has been assigned a value yet&lt;br/&gt;
3. Generating and assigning a new Id value to the Id property&lt;/p&gt;

&lt;p&gt;The last operate at the level of the Id property value and handle:&lt;/p&gt;

&lt;p&gt;1. Determining whether the Id value is empty or not&lt;br/&gt;
2. Generating a new value&lt;/p&gt;

&lt;p&gt;Finally, the fix involved modifying Insert and Save to use these new methods to correctly handle the various scenarios:&lt;/p&gt;

&lt;p&gt;1. The document has no Id property&lt;br/&gt;
2. The document has an Id property but it has an empty value&lt;br/&gt;
3. The document has an Id proeprty and it already has a non-empty value&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|hrh9tr:</customfieldvalue>

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