<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:57:44 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>[SERVER-1686] update doesn&apos;t add &quot;_id&quot; property when upserting</title>
                <link>https://jira.mongodb.org/browse/SERVER-1686</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I think that mongo should populate the &quot;_id&quot; field regardless if a traditional insert is done or a upsert is done.&lt;/p&gt;

&lt;p&gt;Discussed here: &lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/7f986a4609811c1d#&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/7f986a4609811c1d#&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Created test case below:&lt;/p&gt;


&lt;p&gt;import com.google.inject.Guice;&lt;br/&gt;
import com.google.inject.Injector;&lt;br/&gt;
import com.mongodb.BasicDBObject;&lt;br/&gt;
import com.mongodb.DB;&lt;br/&gt;
import com.mongodb.DBCollection;&lt;br/&gt;
import com.mongodb.DBObject;&lt;br/&gt;
import com.xx.rm.GuiceModuleRiskManagement;&lt;/p&gt;

&lt;p&gt;public class Test {&lt;/p&gt;

&lt;p&gt;  private static DB db = null;&lt;/p&gt;

&lt;p&gt;  private static String COLLECTION_NAME = &quot;scoring&quot;;&lt;/p&gt;

&lt;p&gt;  public static void main(String[] args) &lt;/p&gt;
{
    setup();
    testSaveAndRetrieve();
    
  }

&lt;p&gt;  public static void setup() &lt;/p&gt;
{
    Injector injector = Guice.createInjector(new GuiceModuleRiskManagement());
    db = injector.getInstance(DB.class);
    
    DBCollection col = db.getCollection(COLLECTION_NAME);
    col.drop();
  }

&lt;p&gt;  public static void testSaveAndRetrieve()&lt;/p&gt;
{
    String key = &quot;actionItem&quot;;
    
    BasicDBObject dbObject = new BasicDBObject();
    dbObject.put(&quot;id&quot;, key);
    dbObject.put(&quot;test1&quot;, &quot;test1 value&quot;);
    dbObject.put(&quot;test2&quot;, &quot;test2 value&quot;);
    
    dbObject = save(key, dbObject, COLLECTION_NAME);
    
    assert(dbObject.get(&quot;_id&quot;) != null);
  }

&lt;p&gt;  public static BasicDBObject save(final String key, final BasicDBObject dbObject, final String collectionName){&lt;br/&gt;
    final BasicDBObject finder = new BasicDBObject();&lt;br/&gt;
    finder.put(&quot;id&quot;, key);&lt;/p&gt;

&lt;p&gt;    Command updateCommand = new Command() {&lt;br/&gt;
      @Override&lt;br/&gt;
      public Object execute() &lt;/p&gt;
{
        db.getCollection(collectionName).update(finder, dbObject, true, false);
        System.out.println(dbObject.get(&quot;_id&quot;));
        return dbObject;
      }
&lt;p&gt;    };&lt;br/&gt;
    runDatabaseCommand(db, updateCommand);&lt;br/&gt;
    return dbObject;&lt;br/&gt;
  }&lt;/p&gt;

&lt;p&gt;    /**&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Util method to follow proper mongodb idiom to allow all running threads to see changes made.&lt;/li&gt;
	&lt;li&gt;&lt;/li&gt;
	&lt;li&gt;@param db&lt;/li&gt;
	&lt;li&gt;@param command&lt;/li&gt;
	&lt;li&gt;@return&lt;br/&gt;
     */&lt;br/&gt;
    public static Object runDatabaseCommand(DB db, Command command) {&lt;br/&gt;
      Object object = null;&lt;br/&gt;
      try
&lt;div class=&quot;error&quot;&gt;&lt;span class=&quot;error&quot;&gt;Unknown macro: {        db.requestStart();        object = command.execute();         DBObject dbObject = db.getLastError();        if(dbObject.get(&amp;quot;err&amp;quot;) != null){
          throw new RuntimeException(&quot;Error:&quot; + dbObject.get(&quot;err&quot;)); 
        }        db.requestDone();      }&lt;/span&gt; &lt;/div&gt;
&lt;p&gt;catch(Exception e)&lt;/p&gt;
{
        e.printStackTrace();
        throw new RuntimeException(e);
      }
&lt;p&gt;      return object;&lt;br/&gt;
    }&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;    public interface Command &lt;/p&gt;
{

      public Object execute();
      
    }
&lt;p&gt;}&lt;/p&gt;</description>
                <environment></environment>
        <key id="12919">SERVER-1686</key>
            <summary>update doesn&apos;t add &quot;_id&quot; property when upserting</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="-1">Unassigned</assignee>
                                    <reporter username="mwaschkowski">Mark Waschkowski</reporter>
                        <labels>
                    </labels>
                <created>Wed, 25 Aug 2010 20:54:51 +0000</created>
                <updated>Wed, 25 Aug 2010 20:57:50 +0000</updated>
                            <resolved>Wed, 25 Aug 2010 20:57:50 +0000</resolved>
                                    <version>1.6.1</version>
                                                    <component>Usability</component>
                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="17417" author="eliot" created="Wed, 25 Aug 2010 20:57:50 +0000"  >&lt;p&gt;See final comment in group discussion.&lt;/p&gt;

&lt;p&gt;the server does add the _id, but its done server side not client side so you can&apos;t access it they way you are doing&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Wed, 25 Aug 2010 20:57:50 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        13 years, 26 weeks ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></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_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>ian@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            13 years, 26 weeks ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>mwaschkowski</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpgfz:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>21718</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hs7cxj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>