<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:52:26 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>[JAVA-502] cannot remove nulls from array</title>
                <link>https://jira.mongodb.org/browse/JAVA-502</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;I use the following update: &lt;/p&gt;

&lt;p&gt;collection.update(q, new BasicDBObject(&quot;$pull&quot;, new BasicDBObject(&quot;x&quot;,null)) &lt;br/&gt;
//where q is some object which queries the correct doc in the collection and &quot;x&quot; corresponds to an array&lt;/p&gt;

&lt;p&gt;and I receive the following error:&lt;/p&gt;

&lt;p&gt;2012.01.05 10:34:36 root - Error: java.lang.NullPointerException: can&apos;t save a null object &lt;br/&gt;
java.lang.NullPointerException: can&apos;t save a null object &lt;br/&gt;
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:95) &lt;br/&gt;
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:86) &lt;br/&gt;
at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27) &lt;br/&gt;
at com.mongodb.OutMessage.putObject(OutMessage.java:142) &lt;br/&gt;
at com.mongodb.DBApiLayer$MyCollection.update(DBApiLayer.java:345) &lt;br/&gt;
at com.mongodb.DBCollection.update(DBCollection.java:165) &lt;br/&gt;
at com.mongodb.DBCollection.update(DBCollection.java:197) &lt;br/&gt;
at com.mongodb.DBCollection.update(DBCollection.java:209)&lt;/p&gt;

&lt;p&gt;The null is created in the first place as a result of using the $unset:&lt;/p&gt;

&lt;p&gt;collection.update(q, new BasicDBObject(&quot;$unset&quot;, new BasicDBObject(&quot;x&quot;+&quot;.$&quot;,1)))&lt;br/&gt;
//where q is some object which queries the correct doc in the collection and &quot;x&quot; corresponds to an array&lt;/p&gt;

&lt;p&gt;I cannot use the $pull in replacement of $unset because i would require exact matching, which doesn&apos;t seem possible as documented:&lt;br/&gt;
&quot;Because of this feature, to use the embedded doc as a match criteria, you cannot do exact matches on array elements.&quot;&lt;/p&gt;

&lt;p&gt;I had assumed that using the null pointer reference was ok based on the post by Andrew Wharton specified in: &lt;a href=&quot;http://www.mongodb.org/display/DOCS/Java+Types&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.mongodb.org/display/DOCS/Java+Types&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is this the correct way to be doing this? The only other way to accomplish this would be to query the entire array, modify it, then insert it back; but I would rather not do this as this could lead to a race condition.&lt;/p&gt;</description>
                <environment>Java Version:	 1.6.0_23 Sun Microsystems Inc. -- OpenJDK Server VM&lt;br/&gt;
Server: jetty&lt;br/&gt;
Hardware: i386</environment>
        <key id="27762">JAVA-502</key>
            <summary>cannot remove nulls from array</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="scotthernandez">Scott Hernandez</assignee>
                                    <reporter username="jrogers">Josh Rogers</reporter>
                        <labels>
                            <label>driver</label>
                            <label>update</label>
                    </labels>
                <created>Thu, 5 Jan 2012 16:33:39 +0000</created>
                <updated>Thu, 5 Jan 2012 17:08:30 +0000</updated>
                            <resolved>Thu, 5 Jan 2012 17:08:30 +0000</resolved>
                                    <version>2.7.2</version>
                                                    <component>API</component>
                    <component>Documentation</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="77866" author="jrogers" created="Thu, 5 Jan 2012 16:59:57 +0000"  >&lt;p&gt;Sorry. I had assumed that it was a result of passing in a null pointer that I was getting a NullPointerException. It was actually because my query doc was null. I&apos;m not really sure how to close this issue.&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="10038"><![CDATA[Fully Compatible]]></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|hrhbef:</customfieldvalue>

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