<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:49:18 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-4766] Setting a sub-field on update throws a BsonSerializationException</title>
                <link>https://jira.mongodb.org/browse/CSHARP-4766</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;The following should reproduce a MongoDB.Bson.BsonSerializationException on update.&lt;/p&gt;

&lt;p&gt;// &amp;#8212; Model:&lt;/p&gt;

&lt;p&gt;public class Test&lt;/p&gt;
{
&#160; &#160; [BsonId]
&#160; &#160; public object Id \{ get; set; }
&lt;p&gt; = ObjectId.GenerateNewId();&lt;/p&gt;

&lt;p&gt;&#160; &#160; public string Name { get; set; }&lt;/p&gt;

&lt;p&gt;&#160; &#160; public byte[] Data { get; set; }&lt;/p&gt;

&lt;p&gt;&#160; &#160; public BsonDocument Doc { get; set; }&lt;/p&gt;

&lt;p&gt;&#160; &#160; public static IMongoCollection&amp;lt;Test&amp;gt; GetCollection()&lt;br/&gt;
&#160; &#160; &lt;/p&gt;
{
&#160; &#160; &#160; &#160; // Get DB
&#160; &#160; &#160; &#160; var db = TestLibrary.Db.MongoDb;

&#160; &#160; &#160; &#160; return db.GetCollection&amp;lt;Test&amp;gt;(&quot;Tests&quot;);
&#160; &#160; }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;// &amp;#8212; Code:&lt;/p&gt;

&lt;p&gt;var t = new Test();&lt;/p&gt;

&lt;p&gt;t.Name = &quot;TestName&quot;;&lt;/p&gt;

&lt;p&gt;t.Doc = new BsonDocument();&lt;/p&gt;

&lt;p&gt;t.Doc&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;Name&amp;quot;&amp;#93;&lt;/span&gt; = &quot;TestDocName&quot;;&lt;/p&gt;

&lt;p&gt;await c.InsertOneAsync(t, cancellationToken: cancellationToken);&lt;/p&gt;

&lt;p&gt;string? nullString = null;&lt;/p&gt;

&lt;p&gt;await c.UpdateOneAsync(&lt;br/&gt;
&#160; &#160; d =&amp;gt; d.Id == t.Id,&lt;br/&gt;
&#160; &#160; Builders&amp;lt;Test&amp;gt;.Update&lt;br/&gt;
&#160; &#160; &#160; &#160; .Set(d =&amp;gt; d.Data, null)&lt;br/&gt;
&#160; &#160; &#160; &#160; .Set(&quot;Name&quot;, nullString)&lt;br/&gt;
&#160; &#160; &#160; &#160; &lt;b&gt;.Set(&quot;Doc.Name&quot;, nullString), &#160; &#160; &#160;// &amp;lt;-- Source of error&lt;/b&gt;&lt;br/&gt;
&#160; &#160; cancellationToken: cancellationToken);&lt;/p&gt;

&lt;p&gt;MongoDB.Bson.BsonSerializationException: &apos;C# null values of type &apos;BsonValue&apos; cannot be serialized using a serializer of type &apos;BsonValueSerializer&apos;.&apos;&lt;/p&gt;</description>
                <environment></environment>
        <key id="2421752">CSHARP-4766</key>
            <summary>Setting a sub-field on update throws a BsonSerializationException</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</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="2">Won&apos;t Fix</resolution>
                                        <assignee username="oleksandr.poliakov@mongodb.com">Oleksandr Poliakov</assignee>
                                    <reporter username="alex.covecube">Alex Piskarev</reporter>
                        <labels>
                    </labels>
                <created>Sun, 20 Aug 2023 19:52:41 +0000</created>
                <updated>Tue, 5 Sep 2023 21:05:47 +0000</updated>
                            <resolved>Tue, 5 Sep 2023 21:05:47 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="5681273" author="JIRAUSER1273473" created="Tue, 5 Sep 2023 21:05:47 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=alex.covecube&quot; class=&quot;user-hover&quot; rel=&quot;alex.covecube&quot;&gt;alex.covecube&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;After deep investigation of the reported problem we decided not to change current behavior to keep consistent way of working with BsonDocument class. Whenever you are interacting with BsonDocument it should be used together with BsonValues. For example the following code will throw as well:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var document = &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; BsonDocument();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;document[&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;ab&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;; &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;On other hand the following code is working because there is implicit conversion from the C# string to BsonString (in fact C# silently converting string to BsonString so&#160; BsonDocument still working with BsonValue):&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var document = &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; BsonDocument();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;document[&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;ab&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;value&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;; &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;More over if we would support some way to set null as a BsonDocument - what the expected way to read the document back from the database? Should it contains null or BsonNull value?&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;I hope this explains our motivation to keep the existing driver&apos;s behavior.&lt;/p&gt;

&lt;p&gt;For your particular example I can suggest you either create a strongly typed model (replace property of BsonDocument with some POCO) or use the following code snippet whenever you are trying to set the value of BsonDocument:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;stringVar ?? (object)BsonNull.Value;  &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;inside the Set operation it would looks like:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; updateOperation.Set(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;Doc.Name&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;, stringVar ?? (object)BsonNull.Value), &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;I&apos;ll close the ticket, but feel free to add more comments if you will need additional assistance or questions.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Thanks,&lt;/p&gt;

&lt;p&gt;Oleksandr Poliakov&lt;/p&gt;</comment>
                            <comment id="5645693" author="alex.covecube" created="Sun, 20 Aug 2023 19:55:45 +0000"  >&lt;p&gt;This fixes it:&lt;/p&gt;

&lt;p&gt;await c.UpdateOneAsync(&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; d =&amp;gt; d.Id == t.Id,&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Builders&amp;lt;Test&amp;gt;.Update&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; .Set(d =&amp;gt; d.Data, null)&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; .Set(&quot;Name&quot;, nullString)&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;b&gt;.Set(&quot;Doc.Name&quot;, nullString ?? (object)BsonNull.Value),&lt;/b&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; cancellationToken: cancellationToken);&lt;/p&gt;</comment>
                            <comment id="5645692" author="dbeng-pm-bot" created="Sun, 20 Aug 2023 19:52:44 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=alex.covecube&quot; class=&quot;user-hover&quot; rel=&quot;alex.covecube&quot;&gt;alex.covecube&lt;/a&gt;, thank you for reporting this issue! The team will look into it and get back to you soon. &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_14266" key="com.atlassian.jira.plugin.system.customfieldtypes:textarea">
                        <customfieldname>Documentation Changes Summary</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>&lt;p&gt;1. What would you like to communicate to the user about this feature?&lt;br/&gt;
2. Would you like the user to see examples of the syntax and/or executable code and its output?&lt;br/&gt;
3. Which versions of the driver/connector does this apply to?&lt;/p&gt;</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i252ww:</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>