<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:56:18 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-1182] Add $noop operation to update or another insert if not exist feature</title>
                <link>https://jira.mongodb.org/browse/SERVER-1182</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Add a $noop operations so you can effectively do an insert if some criteria doesn&apos;t already exist.&lt;/p&gt;

&lt;p&gt;db.coll.update({_id:25, name:&quot;John&quot;}, {$noop:1}, true, false)&lt;/p&gt;

&lt;p&gt;This question came up in IRC and is the reason for this request: &quot;I want to insert some data into a collection if and only if it doesn&apos;t exist already?&quot;&lt;/p&gt;

&lt;p&gt;This can be done with a query + insert but would be closer to the RDBMS version (which is wrapped in a transaction normally) using the syntax above (which is atomic).&lt;/p&gt;

&lt;p&gt;I could also see this working by using a null second param for update (this is not currently allowed), but the $noop is clearer.&lt;/p&gt;</description>
                <environment></environment>
        <key id="12057">SERVER-1182</key>
            <summary>Add $noop operation to update or another insert if not exist feature</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="2">Won&apos;t Fix</resolution>
                                        <assignee username="eliot">Eliot Horowitz</assignee>
                                    <reporter username="scotthernandez">Scott Hernandez</reporter>
                        <labels>
                    </labels>
                <created>Wed, 2 Jun 2010 13:30:09 +0000</created>
                <updated>Wed, 7 Jul 2010 12:09:35 +0000</updated>
                            <resolved>Wed, 7 Jul 2010 12:09:35 +0000</resolved>
                                    <version>1.5.2</version>
                                                    <component>Querying</component>
                                        <votes>2</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="15513" author="eliot" created="Wed, 7 Jul 2010 12:09:35 +0000"  >&lt;p&gt;Actually - this will work fine today&lt;/p&gt;


&lt;p&gt;&amp;gt; db.foo.update( &lt;/p&gt;
{ a : 1 , b : 2 }
&lt;p&gt; , { $set : {} } , true )&lt;/p&gt;

&lt;p&gt;$set : {} === $noop&lt;/p&gt;</comment>
                            <comment id="15512" author="dwight_10gen" created="Wed, 7 Jul 2010 11:57:33 +0000"  >&lt;p&gt;what&apos;s wrong with just doing an insert, and having it fail because of dup _id if the value is already there?&lt;/p&gt;</comment>
                            <comment id="15259" author="erickt" created="Thu, 1 Jul 2010 02:55:14 +0000"  >&lt;p&gt;I got an implementation for this patch here: &lt;a href=&quot;http://github.com/erickt/mongo&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/erickt/mongo&lt;/a&gt;.&lt;/p&gt;</comment>
                            <comment id="14932" author="eliot" created="Tue, 22 Jun 2010 04:29:49 +0000"  >&lt;p&gt;@erick yes&lt;/p&gt;</comment>
                            <comment id="14930" author="erickt" created="Tue, 22 Jun 2010 02:46:43 +0000"  >&lt;p&gt; Just to be clear, is this what you are expecting?&lt;/p&gt;

&lt;p&gt;&amp;gt; db.coll.find();&lt;br/&gt;
&amp;gt; db.coll.update({_id:25, name:&quot;John&quot;}, {$noop:1}, true, false);&lt;br/&gt;
&amp;gt; db.coll.find();&lt;br/&gt;
{_id:25, name:&quot;John&quot;}&lt;br/&gt;
&amp;gt; db.coll.update(&lt;/p&gt;
{name:&quot;John&quot;}
&lt;p&gt;, {$noop:1}, true, false);&lt;br/&gt;
&amp;gt; db.coll.find();&lt;br/&gt;
{_id:25, name:&quot;John&quot;}&lt;/p&gt;</comment>
                            <comment id="14539" author="scotthernandez" created="Wed, 2 Jun 2010 13:51:29 +0000"  >&lt;p&gt;Understood, but that will replace the item at _id:5 with the document {_id:5, x:5 }. if the existing document already exists it will override it, or update it.&lt;/p&gt;

&lt;p&gt;This could also be done with a insert() with values that are in a unique index but that has other issues since any component of the compound index that is missing a field could cause a violation to the uniqueness because missing fields result in a null value in the index.&lt;/p&gt;

&lt;p&gt;What you have suggested does not satisfy the &quot;insert only if missing&quot; part of the problem.&lt;/p&gt;</comment>
                            <comment id="14538" author="eliot" created="Wed, 2 Jun 2010 13:32:31 +0000"  >&lt;p&gt;The canonical way to do this is&lt;/p&gt;

&lt;p&gt;update( &lt;/p&gt;
{ _id : 5 }
&lt;p&gt; , &lt;/p&gt;
{ x : 5 }
&lt;p&gt; , true )&lt;/p&gt;


&lt;p&gt;where the left side is the unique constraint&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>7.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Wed, 2 Jun 2010 13:32:31 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        13 years, 33 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, 33 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>dwight@mongodb.com</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>erickt</customfieldvalue>
            <customfieldvalue>scotthernandez</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrplxj:</customfieldvalue>

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

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

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