<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:22 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-282] Empty UpdateBuilder will null out a document</title>
                <link>https://jira.mongodb.org/browse/CSHARP-282</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Using the code below, if a call is made to class method Handle() with an evnt with out any Changes this will pass an initialized but empty UpdateBuilder() to the MongoCollection Update command which will null out all the values in the document. I was expecting no changes to be made.&lt;/p&gt;

&lt;p&gt;public class xyz&lt;br/&gt;
{&lt;br/&gt;
	readonly MongoCollection&amp;lt;T&amp;gt; _docs;&lt;/p&gt;

&lt;p&gt;	public void Update(dynamic id, IMongoUpdate update)&lt;/p&gt;
        {
            _docs.Update(new QueryDocument(&quot;_id&quot;, id), update);
        }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;public class abc&lt;br/&gt;
{&lt;br/&gt;
        readonly xyz _atttributeTypes;&lt;/p&gt;

&lt;p&gt;        public void Handle(AttributeTypeUpdated evnt)&lt;/p&gt;
        { 
            var update = new UpdateBuilder();
            foreach (var change in evnt.Changes)
                update.SetWrapped(change.Key, change.Value);
            _atttributeTypes.Update(evnt.EventSourceId, update);
        }
&lt;p&gt;}&lt;/p&gt;

</description>
                <environment>Windows Server 2008</environment>
        <key id="20109">CSHARP-282</key>
            <summary>Empty UpdateBuilder will null out a document</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="woaksie">John Woakes</reporter>
                        <labels>
                    </labels>
                <created>Mon, 25 Jul 2011 20:32:17 +0000</created>
                <updated>Thu, 2 Apr 2015 18:28:11 +0000</updated>
                            <resolved>Tue, 26 Jul 2011 21:43:41 +0000</resolved>
                                    <version>1.1</version>
                                    <fixVersion>1.2</fixVersion>
                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="44847" author="woaksie" created="Wed, 27 Jul 2011 16:31:12 +0000"  >&lt;p&gt;That&apos;s what I thought. The one difference is I used the public ToBsonDocument() method on UpdateBuilder to get the document where you created a new internal property Document.&lt;/p&gt;</comment>
                            <comment id="44831" author="rstam" created="Wed, 27 Jul 2011 16:10:38 +0000"  >&lt;p&gt;That&apos;s reassuring. Thanks again for your help with this.&lt;/p&gt;</comment>
                            <comment id="44828" author="woaksie" created="Wed, 27 Jul 2011 16:08:08 +0000"  >&lt;p&gt;I just looked at your solution and it is exactly the same as what we implemented at our end. Glad to be part of the process.&lt;/p&gt;</comment>
                            <comment id="44639" author="rstam" created="Tue, 26 Jul 2011 21:44:33 +0000"  >&lt;p&gt;John: thanks for your help on this. This is a kind of subtle edge case I hadn&apos;t considered, and your feedback as been very helpful.&lt;/p&gt;</comment>
                            <comment id="44638" author="rstam" created="Tue, 26 Jul 2011 21:43:42 +0000"  >&lt;p&gt;MongoCollection.Update now throws an ArgumentException when called with an empty UpdateBuilder. This prevents accidentally clearing all elements of a document (if that&apos;s what you want say so explicitly by using Update.Replace with an empty BsonDocument).&lt;/p&gt;</comment>
                            <comment id="44601" author="woaksie" created="Tue, 26 Jul 2011 19:27:05 +0000"  >&lt;p&gt;Thank for listening Robert. It helped me too to talk it through.&lt;/p&gt;</comment>
                            <comment id="44596" author="rstam" created="Tue, 26 Jul 2011 19:22:58 +0000"  >&lt;p&gt;New fix proposed. See previous comments.&lt;/p&gt;</comment>
                            <comment id="44594" author="rstam" created="Tue, 26 Jul 2011 19:22:33 +0000"  >&lt;p&gt;I agree. I would have listed that as option 3 if it had occurred to me.&lt;/p&gt;

&lt;p&gt;I will reopen this ticket and the fix will be to throw an exception if the UpdateBuilder is empty.&lt;/p&gt;

&lt;p&gt;Thanks for your help on this.&lt;/p&gt;</comment>
                            <comment id="44593" author="woaksie" created="Tue, 26 Jul 2011 19:14:42 +0000"  >&lt;p&gt;Actually an exception makes sense. The UpdateBuilder is in an incomplete state not suitable for execution...&lt;/p&gt;</comment>
                            <comment id="44589" author="woaksie" created="Tue, 26 Jul 2011 19:08:32 +0000"  >&lt;p&gt;What we are going in our code is throw an exception. We don&apos;t want developers calling this with no changes. &lt;/p&gt;

&lt;p&gt;Obviously this won&apos;t work for everyone but the results if you call this with an empty builder are pretty harsh if that is not what you intended. We actually lost production data because of this &quot;feature&quot;.&lt;/p&gt;</comment>
                            <comment id="44579" author="rstam" created="Tue, 26 Jul 2011 18:20:25 +0000"  >&lt;p&gt;Theoretically we could change the driver to handle an empty UpdateBuilder differently than an empty JSON document. The server may not know the difference, but the driver could.&lt;/p&gt;

&lt;p&gt;One question would be: what to do when the UpdateBuilder is empty?&lt;/p&gt;

&lt;p&gt;1. Don&apos;t even call the server&lt;br/&gt;
2. Call the server with an update document that does nothing (not sure how, there is no $nop operator)&lt;/p&gt;

&lt;p&gt;The problem with the first is that we can&apos;t return a SafeModeResult if SafeMode is on, which the caller might be using to verify that the Update happened. The problem with the second is that I don&apos;t think it&apos;s possible to construct an update document that does nothing.&lt;/p&gt;

&lt;p&gt;Any further thoughts?&lt;/p&gt;</comment>
                            <comment id="44566" author="woaksie" created="Tue, 26 Jul 2011 17:48:30 +0000"  >&lt;p&gt;I understand that if you execute an Update() with an empty json document that that is saying replace the document with an empty document.&lt;/p&gt;

&lt;p&gt;This is how I understand this - The UpdateBuilder is an abstraction that encapsulates updating parts of a document. It just happens that if the UpdateBuilder is empty it causes a different overloaded update() to execute on the server. From the driver&apos;s point of view an empty UpdateBuilder object conceptually should not replace the document with an empty document, it is just an unfortunate result of how the UpdateBuilder serializes its commands to JSon.&lt;/p&gt;</comment>
                            <comment id="44561" author="rstam" created="Tue, 26 Jul 2011 17:31:59 +0000"  >&lt;p&gt;I checked with the server folks and they confirmed that it works this way by design.&lt;/p&gt;</comment>
                            <comment id="44411" author="woaksie" created="Tue, 26 Jul 2011 01:31:35 +0000"  >&lt;p&gt;Ok, I was wondering if that might be the case. It is not the desired behaviour for us so we will have to guard against this happening in our code.&lt;/p&gt;</comment>
                            <comment id="44381" author="rstam" created="Mon, 25 Jul 2011 20:54:13 +0000"  >&lt;p&gt;Here&apos;s the online documentation for update:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.mongodb.org/display/DOCS/Updating#Updating-update%28%29&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.mongodb.org/display/DOCS/Updating#Updating-update%28%29&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An empty document value for objNew is considered a replacement document instead of an empty list of update operators.&lt;/p&gt;

&lt;p&gt;You should check in the client code for an empty update document and just don&apos;t call the server in that case.&lt;/p&gt;</comment>
                            <comment id="44380" author="rstam" created="Mon, 25 Jul 2011 20:51:27 +0000"  >&lt;p&gt;I think that&apos;s just the way the server handles empty updates. See this mongo shell transcript:&lt;/p&gt;

&lt;p&gt;&amp;gt; db.test.find()&lt;/p&gt;
{ &quot;_id&quot; : ObjectId(&quot;4e2dd696f7cd79c91b0f85f9&quot;), &quot;x&quot; : 1, &quot;y&quot; : 2 }
&lt;p&gt;&amp;gt; db.test.update(&lt;/p&gt;
{x:1}
&lt;p&gt;,{})&lt;br/&gt;
&amp;gt; db.test.find()&lt;/p&gt;
{ &quot;_id&quot; : ObjectId(&quot;4e2dd696f7cd79c91b0f85f9&quot;) }
&lt;p&gt;&amp;gt;&lt;/p&gt;

&lt;p&gt;This is showing the exact same behavior without the C# driver involved.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10011"><![CDATA[Minor Change]]></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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrh8nb:</customfieldvalue>

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