<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:54:09 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-453] $iset - set fields only on insert when upserting</title>
                <link>https://jira.mongodb.org/browse/SERVER-453</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;It&apos;d be nice if there was the ability to tell Mongo on an upsert, &quot;set this field only if a new document is created&quot;.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;db.users.update( &lt;/p&gt;
{ foo: &apos;bar&apos;}
&lt;p&gt;, { $set: &lt;/p&gt;
{ baz: &apos;bap&apos; }
&lt;p&gt;, $iset: &lt;/p&gt;
{ create_time: new Date() }
&lt;p&gt; }, true)&lt;/p&gt;


&lt;p&gt;You could also imagine an equivalent to only set fields when updating but not inserting, although when updating there are more things you might want to do than just set ($inc, $push, etc), this may need more thought as to best approach. Perhaps $updateonly which can then contain any number of possible modifications, e.g. { $updateonly: { $inc: &lt;/p&gt;
{ modifications: 1 }
&lt;p&gt;, $set: &lt;/p&gt;
{ modify_time: new Date() }
&lt;p&gt; }&lt;/p&gt;</description>
                <environment></environment>
        <key id="10937">SERVER-453</key>
            <summary>$iset - set fields only on insert when upserting</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</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="3">Duplicate</resolution>
                                        <assignee username="eliot">Eliot Horowitz</assignee>
                                    <reporter username="ibwhite">Ian White</reporter>
                        <labels>
                    </labels>
                <created>Thu, 3 Dec 2009 11:10:53 +0000</created>
                <updated>Mon, 18 Nov 2013 16:15:28 +0000</updated>
                            <resolved>Thu, 21 Apr 2011 15:45:50 +0000</resolved>
                                    <version>1.1.3</version>
                                                    <component>Querying</component>
                                        <votes>15</votes>
                                    <watches>15</watches>
                                                                                                                <comments>
                            <comment id="457833" author="dblock" created="Mon, 18 Nov 2013 16:15:28 +0000"  >&lt;p&gt;In my case I am doing a $set for the same value, I presume I am paying the price for that. It would be useful to know how expensive the operation is. Of course, $insert (from above) is what I mean to do, +1 for that.&lt;/p&gt;</comment>
                            <comment id="29427" author="eliot" created="Thu, 21 Apr 2011 15:45:50 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-340&quot; title=&quot;$setOnInsert modifier for upsert&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-340&quot;&gt;&lt;del&gt;SERVER-340&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="24896" author="wardrop" created="Mon, 28 Feb 2011 23:34:12 +0000"  >&lt;p&gt;I was after a similar thing the other week. I&apos;m writing an object mapper that basically builds a queue of document operations, until a commit method is called. The operations are stored in a hash against the actual operator, e.g. {&apos;$set&apos; =&amp;gt; &lt;/p&gt;
{name: &apos;Bill&apos;}
&lt;p&gt;, &apos;$inc&apos; =&amp;gt; {age: 2}}. If the document is new (i.e. if the object mapper doesn&apos;t know of an _id), then I obviously need some way to run these operations. The best I could come up with was issuing an insert command, for the sole purpose of generating an _id, and then doing an update so I could apply the queued operations.&lt;/p&gt;

&lt;p&gt;So the main use case I see for this is being able to apply modifiers (e.g. $set, $inc, etc) during an insert operation. The above suggestion would accommodate this (not ideal, but a solution none the less).&lt;/p&gt;</comment>
                            <comment id="24335" author="eliot" created="Sun, 20 Feb 2011 17:47:00 +0000"  >&lt;p&gt;@keith, yes, if this is part of the update spec it&apos;ll work fine with findAndModify&lt;/p&gt;</comment>
                            <comment id="24333" author="keithbranton" created="Sun, 20 Feb 2011 17:34:09 +0000"  >&lt;p&gt;+1 for Matt&apos;s suggestion of $insert and $update&lt;/p&gt;

&lt;p&gt;Eliot closed &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2595&quot; title=&quot;Allow specification of new document in findAndModify in upsert operation&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2595&quot;&gt;&lt;del&gt;SERVER-2595&lt;/del&gt;&lt;/a&gt; as a duplicate of this - so presumably this will work with findAndModify as well as update - that was what &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2595&quot; title=&quot;Allow specification of new document in findAndModify in upsert operation&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2595&quot;&gt;&lt;del&gt;SERVER-2595&lt;/del&gt;&lt;/a&gt; was about.&lt;/p&gt;</comment>
                            <comment id="16322" author="tcurdt" created="Fri, 30 Jul 2010 19:08:34 +0000"  >&lt;p&gt;This seems to be a duplicate of &lt;a href=&quot;http://jira.mongodb.org/browse/SERVER-340&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/SERVER-340&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="13499" author="mmastrac" created="Wed, 7 Apr 2010 21:40:47 +0000"  >&lt;p&gt;I ran into this missing functionality today. An alternative syntax might be something like this (using $insert and $update to gate operations):&lt;/p&gt;

&lt;p&gt;db.users.update( &lt;/p&gt;
{ foo: &apos;bar&apos;}
&lt;p&gt;, { $set: &lt;/p&gt;
{ baz: &apos;bap&apos; }
&lt;p&gt;, $insert: &lt;/p&gt;
{ create_time: new Date() }
&lt;p&gt;, $update: { $inc: &lt;/p&gt;
{&quot;update_count&quot;, 1}
&lt;p&gt;  } }, true) &lt;/p&gt;</comment>
                            <comment id="11263" author="eliot" created="Thu, 3 Dec 2009 11:29:38 +0000"  >&lt;p&gt;i think the solution for upsert will also handle this&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                        <issuelink>
            <issuekey id="10807">SERVER-390</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="10706">SERVER-340</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>8.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Thu, 3 Dec 2009 11:29:38 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        10 years, 13 weeks, 2 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[<s><a href='https://jira.mongodb.org/browse/SERVER-390'>SERVER-390</a></s>]]></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>
                            10 years, 13 weeks, 2 days 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>dblock</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>ibwhite</customfieldvalue>
            <customfieldvalue>keithbranton</customfieldvalue>
            <customfieldvalue>mmastrac</customfieldvalue>
            <customfieldvalue>wardrop</customfieldvalue>
            <customfieldvalue>tcurdt</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpu6v:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>22259</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|ht00nz:</customfieldvalue>

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