<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:35: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>[GODRIVER-971] ability to marshal empty slices as bson [] rather than nil</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-971</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;If a field in a struct is a slice, and it has no elements, and it is not omit empty, then it&#8217;s BSON value is nil.&lt;/p&gt;

&lt;p&gt;This means that you can&#8217;t treat it like an array (e.g. use $push,) and we ran into issues with $in as well.&lt;/p&gt;

&lt;p&gt;In MGO these types were [], and it appears that our application depends on this.&lt;/p&gt;</description>
                <environment></environment>
        <key id="740614">GODRIVER-971</key>
            <summary>ability to marshal empty slices as bson [] rather than nil</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="13203">Gone away</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="sam.kleinman">Sam Kleinman</reporter>
                        <labels>
                            <label>evg</label>
                            <label>mgocompat</label>
                    </labels>
                <created>Wed, 17 Apr 2019 20:49:14 +0000</created>
                <updated>Fri, 27 Oct 2023 20:01:26 +0000</updated>
                            <resolved>Mon, 13 Jan 2020 15:11:14 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="2721891" author="divjot.arora" created="Mon, 13 Jan 2020 15:11:14 +0000"  >&lt;p&gt;This was done as part of &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-1362&quot; title=&quot;Add SliceCodec for mgocompat&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-1362&quot;&gt;&lt;del&gt;GODRIVER-1362&lt;/del&gt;&lt;/a&gt; and will be released with the mgo-compatible registry in 1.3.0.&lt;/p&gt;</comment>
                            <comment id="2321031" author="samk" created="Thu, 11 Jul 2019 14:21:43 +0000"  >&lt;p&gt;I think in order to support a migration path from mgobson to this bson library we &lt;b&gt;need&lt;/b&gt; a top level switch. We have enough types (and some vendored types, plus type aliases/etc.) that it doesn&apos;t seem particularly tractable to just &quot;omitempty&quot; everywhere. Also, while omiting empty fields will fix some tests, it&apos;s not the same semantics as mgobson. &lt;/p&gt;</comment>
                            <comment id="2218479" author="david.golden" created="Thu, 18 Apr 2019 20:42:24 +0000"  >&lt;p&gt;It may be consistent with encoding/json, but because we&apos;re creating documents for a database where shape matters for what operators can be used, there&apos;s a reasonable argument to be made to keep the mgo behavior.  OTOH, a struct with a nil slice field wouldn&apos;t roundtrip, as the decoded struct would an allocated slice field.  That&apos;s not great, either.&lt;/p&gt;

&lt;p&gt;I think we should investigate what other static language drivers do in this situation?  If we do keep the current behavior, we should probably document this clearly and recommend omitempty for slice type fields.&lt;/p&gt;

&lt;p&gt;Secondary question, if this behavior changes, should it also change for nil &lt;tt&gt;map&lt;span class=&quot;error&quot;&gt;&amp;#91;X&amp;#93;&lt;/span&gt;Y&lt;/tt&gt; for consistency?&lt;/p&gt;</comment>
                            <comment id="2218477" author="samk" created="Thu, 18 Apr 2019 20:42:12 +0000"  >&lt;p&gt;I think that&apos;s fine generally, I just don&apos;t have a path out of using mgobson without some way to control this.&lt;/p&gt;</comment>
                            <comment id="2218465" author="kris.brandow" created="Thu, 18 Apr 2019 20:30:56 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=sam.kleinman&quot; class=&quot;user-hover&quot; rel=&quot;sam.kleinman&quot;&gt;sam.kleinman&lt;/a&gt;, the current behavior is that if the slice is &lt;tt&gt;nil&lt;/tt&gt; we will make a BSON Null and if it&apos;s of zero length, but allocated then we will make it a BSON Array that&apos;s empty. This is consistent with the &lt;tt&gt;encoding/json&lt;/tt&gt; package: &lt;a href=&quot;https://play.golang.org/p/lD5UqxAKtKj&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://play.golang.org/p/lD5UqxAKtKj&lt;/a&gt;.&lt;/p&gt;</comment>
                            <comment id="2217779" author="samk" created="Thu, 18 Apr 2019 14:15:06 +0000"  >&lt;p&gt;Both cases, I think. Given that you can use the append variable to a nil slice, and that slices in structs are nil in the default construction, both are important to us.&lt;/p&gt;</comment>
                            <comment id="2217378" author="david.golden" created="Thu, 18 Apr 2019 01:19:40 +0000"  >&lt;blockquote&gt;&lt;p&gt;If a field in a struct is a slice, and it has no elements&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;When you say &quot;has no elements&quot;, do you mean the field is nil (i.e. zero value), or that the field is non-nil but has length zero, or are both cases a problem?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="1857637">GODRIVER-2137</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="883798">GODRIVER-1216</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <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_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>GODRIVER-226</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|huo4zj:</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>