<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:34 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-356] Atomic update (Set) not work if object value null</title>
                <link>https://jira.mongodb.org/browse/CSHARP-356</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;var message = new SomeClassWithFieldCode();&lt;br/&gt;
//if code is null it will not update field, need to use BsonNull.Value in case if object value null&lt;br/&gt;
var update = Update.Set(&quot;Code&quot;, message.Code); // Code is null&lt;br/&gt;
mongoCollection.Update(Query.EQ(&quot;_id&quot;, message.Id), update);&lt;/p&gt;

&lt;p&gt;I suppose driver should replace null with BsonNull.Value internally rather than set it manually on each update in case if some property value equals to null.&lt;/p&gt;

&lt;p&gt;Thank you. &lt;/p&gt;</description>
                <environment></environment>
        <key id="25037">CSHARP-356</key>
            <summary>Atomic update (Set) not work if object value null</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="anorsich">Andrew Orsich</reporter>
                        <labels>
                            <label>c#</label>
                            <label>driver</label>
                    </labels>
                <created>Thu, 17 Nov 2011 08:22:14 +0000</created>
                <updated>Thu, 2 Apr 2015 18:28:28 +0000</updated>
                            <resolved>Sat, 18 Feb 2012 16:25:38 +0000</resolved>
                                    <version>1.3</version>
                                    <fixVersion>1.4</fixVersion>
                                                        <votes>1</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="416796" author="markwalsh.liverpool" created="Tue, 3 Sep 2013 15:36:52 +0000"  >&lt;p&gt;Just incase you didn&apos;t get notified on Stackoverflow Robert.  Can I ask why this throws an Argument Null Exception when the value is null? Rather than just default to BsonNull.Value when the value is null. I am refactoring after a driver update and this is killing me (it never used to throw an exception).&lt;/p&gt;</comment>
                            <comment id="89818" author="rstam" created="Sat, 18 Feb 2012 16:25:38 +0000"  >&lt;p&gt;All Update builder methods now throw an ArgumentNullException when called with an invalid null argument.&lt;/p&gt;</comment>
                            <comment id="89817" author="rstam" created="Sat, 18 Feb 2012 16:23:57 +0000"  >&lt;p&gt;Nulls are handled slightly differently when you are in the object mapping world vs the object model (BsonDocument) world. A C# null is mapped by the serialization layer to a BsonNull.Value, but C# null is not a valid BsonValue.&lt;/p&gt;

&lt;p&gt;So in our example above, the Code property is C# null in your data model and will be mapped to BsonNull.Value in your database.&lt;/p&gt;</comment>
                            <comment id="67828" author="anorsich" created="Mon, 21 Nov 2011 08:21:35 +0000"  >&lt;p&gt;But when you writing Update.Set you don&apos;t want to omit this value, you want update it. In case of XDocument you always make update of entire document. &lt;br/&gt;
Same behavior for the usual save? &lt;/p&gt;

&lt;p&gt;  message.Code = null;&lt;br/&gt;
  messageCollection.Save(message);  // this also keep Code in previous state and not update it with null?&lt;/p&gt;

&lt;p&gt;Also, is there any way to control this behavior via some settings? &lt;/p&gt;</comment>
                            <comment id="67694" author="rstam" created="Fri, 18 Nov 2011 23:09:23 +0000"  >&lt;p&gt;Null is never automatically converted to BsonNull.Value because there are many cases where null means to omit the item (it is part of the rules of functional construction of BsonDocuments, which by the way works the same way in .NET&apos;s XDocument classes).&lt;/p&gt;

&lt;p&gt;The intended way to handle null in your sample case is:&lt;/p&gt;

&lt;p&gt;var update = Update.Set(&quot;Code&quot;, (BsonValue) message.Code ?? BsonNull.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|hrh87j:</customfieldvalue>

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