<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:52:10 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-387] DBCollection#findOne(DBObject o, DBObject fields) doesn&apos;t markAsPartialObject</title>
                <link>https://jira.mongodb.org/browse/JAVA-387</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Looks like a bug in the driver where markAsPartialObject is not set when querying with findOne(DBObject o, DBObject fields).&lt;br/&gt;
In effect a collection.save(object) causes loss of unselected fields.&lt;/p&gt;

&lt;p&gt;This code illustrates the behavior (at least on my machine):&lt;/p&gt;

&lt;p&gt;DBCollection col = new Mongo(&quot;localhost&quot;).getDB(&quot;test&quot;).getCollection(&quot;test&quot;);&lt;br/&gt;
col.drop();&lt;/p&gt;

&lt;p&gt;// insert document with two fields:&lt;br/&gt;
DBObject t = BasicDBObjectBuilder.start(&quot;name&quot;, &quot;marc&quot;).add(&quot;company&quot;, &quot;viadesk&quot;).get();&lt;br/&gt;
col.save(t);&lt;/p&gt;

&lt;p&gt;// prepare query and field selector:&lt;br/&gt;
DBObject q = BasicDBObjectBuilder.start(&quot;name&quot;, &quot;marc&quot;).get();&lt;br/&gt;
DBObject f = BasicDBObjectBuilder.start(&quot;name&quot;, 1).get();&lt;/p&gt;

&lt;p&gt;// call findOne to get object, returns full document:&lt;br/&gt;
DBObject r = col.findOne(q);&lt;br/&gt;
System.out.println(&quot;findOne (all fields):&quot;);&lt;br/&gt;
System.out.println(r);&lt;br/&gt;
System.out.println(&quot;isPartial: &quot; + r.isPartialObject());&lt;br/&gt;
System.out.println();&lt;/p&gt;

&lt;p&gt;// call findOne to get object, now with only &apos;name&apos; field,&lt;br/&gt;
// notice isPartialObject returns false!&lt;br/&gt;
r = col.findOne(q, f);&lt;br/&gt;
System.out.println(&quot;findOne (selected fields):&quot;);&lt;br/&gt;
System.out.println(r);&lt;br/&gt;
System.out.println(&quot;isPartial: &quot; + r.isPartialObject());&lt;br/&gt;
System.out.println();&lt;/p&gt;

&lt;p&gt;// try to save the returned document, this should throw an&lt;br/&gt;
// IllegalArgumentException: can&apos;t save partial objects&lt;br/&gt;
// but is doesn&apos;t:&lt;br/&gt;
col.save(r);&lt;br/&gt;
System.out.println(&quot;saved document&quot;);&lt;br/&gt;
System.out.println();&lt;/p&gt;

&lt;p&gt;// call findOne to get object, now the &apos;company&apos; field gone &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/sad.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;br/&gt;
r = col.findOne(q);&lt;br/&gt;
System.out.println(&quot;findOne (all fields):&quot;);&lt;br/&gt;
System.out.println(r);&lt;br/&gt;
System.out.println(&quot;isPartial: &quot; + r.isPartialObject());&lt;br/&gt;
System.out.println();&lt;/p&gt;

</description>
                <environment>/Applications/mongodb-osx-x86_64-1.8.1/bin/mongod&lt;br/&gt;
/lib/mongo-2.6.3.jar</environment>
        <key id="18690">JAVA-387</key>
            <summary>DBCollection#findOne(DBObject o, DBObject fields) doesn&apos;t markAsPartialObject</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="antoine">Antoine Girbal</assignee>
                                    <reporter username="leidner">Marc Leidner</reporter>
                        <labels>
                    </labels>
                <created>Fri, 24 Jun 2011 19:01:47 +0000</created>
                <updated>Wed, 10 Aug 2011 05:33:34 +0000</updated>
                            <resolved>Tue, 19 Jul 2011 01:04:29 +0000</resolved>
                                    <version>2.6.3</version>
                                    <fixVersion>2.6.4</fixVersion>
                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="42956" author="antoine" created="Tue, 19 Jul 2011 01:04:29 +0000"  >&lt;p&gt;thanks for report.&lt;br/&gt;
The check was only done in DBCursor, which findOne doesnt use.&lt;/p&gt;</comment>
                            <comment id="42955" author="auto" created="Tue, 19 Jul 2011 01:04:17 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;agirbal&apos;, u&apos;name&apos;: u&apos;agirbal&apos;, u&apos;email&apos;: u&apos;antoine@10gen.com&apos;}
&lt;p&gt;Message: - &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-387&quot; title=&quot;DBCollection#findOne(DBObject o, DBObject fields) doesn&amp;#39;t markAsPartialObject&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-387&quot;&gt;&lt;del&gt;JAVA-387&lt;/del&gt;&lt;/a&gt;: DBCollection#findOne(DBObject o, DBObject fields) doesn&apos;t markAsPartialObject&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/3aee72f1cf814bcbc786a2e04dbce12a81f4cc14&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/3aee72f1cf814bcbc786a2e04dbce12a81f4cc14&lt;/a&gt;&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|hrhbx3:</customfieldvalue>

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