<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:00:45 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-2642] Allow Modifier Operations During Insert</title>
                <link>https://jira.mongodb.org/browse/SERVER-2642</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;A large convenience to developers, would be the ability to use modifier operations during an insert. I propose the addition of a second argument for &quot;insert&quot;, the purpose of which would be to accept a hash of modifier operations . E.g. db.test.insert({}, {$set : &lt;/p&gt;
{name: &apos;bob&apos;}
&lt;p&gt;, $inc: {age: 3}})&lt;/p&gt;

&lt;p&gt;The purpose of the previous example would be to insert a new document (with an auto-generated ID), and then apply the given modifiers (or what one may call the &quot;update&quot; clause) to that new document. Basically, there needs to be some way to apply modifier operations during an insert, as this is a relatively common requirement for object mappers and the like. In an object mapper I&apos;m writing at the moment, the only work-around I&apos;ve found is to issue a blank insert (for the sole purpose of inserting a new document and generating an ID), followed by an update (or a findAndModify in my specific circumstance).&lt;/p&gt;</description>
                <environment></environment>
        <key id="14933">SERVER-2642</key>
            <summary>Allow Modifier Operations During Insert</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="2">Won&apos;t Fix</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="wardrop">Tom Wardrop</reporter>
                        <labels>
                    </labels>
                <created>Mon, 28 Feb 2011 23:47:07 +0000</created>
                <updated>Wed, 10 Dec 2014 23:14:58 +0000</updated>
                            <resolved>Tue, 2 Apr 2013 19:49:00 +0000</resolved>
                                                                    <component>Write Ops</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="304440" author="eliot" created="Tue, 2 Apr 2013 19:48:56 +0000"  >&lt;p&gt;Tom - _id generated on the client are unique (part of it is machine/pid)&lt;/p&gt;</comment>
                            <comment id="24923" author="wardrop" created="Tue, 1 Mar 2011 02:55:51 +0000"  >&lt;p&gt;But that&apos;s the thing, unless I have a document _id, I don&apos;t want to update, I want to insert. So basically, the logic in my code is this:&lt;/p&gt;

&lt;p&gt;if this._id is null then insert a new document,&lt;br/&gt;
otherwise, update existing document.&lt;/p&gt;

&lt;p&gt;Whether I&apos;m inserting a new document or updating an existing one, the operations I have queued in my program are in the form of modifiers, e.g. {$set : &lt;/p&gt;
{...}
&lt;p&gt;, $inc : {...}}. Insert doesn&apos;t allow me to use modifiers like $set, so I have to use update(). What I&apos;m doing currently is, when the document doesn&apos;t already exist (i.e. when I don&apos;t have an _id), I insert an empty document (for the sole purpose of getting an _id), and then do an update on it.&lt;/p&gt;

&lt;p&gt;If however you&apos;re correct in that the _id is generated by the client, and not the server, then yes, all my problems could be solved by just generating an ID in my code (using the Ruby driver&apos;s BSON::ObjectId.new). I was under the impression though that _id&apos;s are generated on the server to ensure uniqueness? Is there no risk of _id clashes if they&apos;re generated on the client?&lt;/p&gt;</comment>
                            <comment id="24920" author="scotthernandez" created="Tue, 1 Mar 2011 02:30:25 +0000"  >&lt;p&gt;So what should the _id be? This makes no sense, either you want to match on some set of criteria or not.&lt;/p&gt;

&lt;p&gt;You do know that the _id field is usually set automatically by the client (driver), not the server? If you want your mapper to create an _id automatically, just create a new ObjectId().&lt;/p&gt;</comment>
                            <comment id="24914" author="wardrop" created="Tue, 1 Mar 2011 00:37:03 +0000"  >&lt;p&gt;I think I may have found a solution to this using upsert. It&apos;s not pretty, and I would still like to see this suggestion implemented, but this work-around seems to get the job done in the mean time:&lt;/p&gt;

&lt;p&gt;db.test.update(&lt;/p&gt;
{insert: &quot;a unique value of some sort&quot;}
&lt;p&gt;, {$set : &lt;/p&gt;
{name: &apos;bob&apos;}
&lt;p&gt;, $inc: &lt;/p&gt;
{age: 3}
&lt;p&gt;, $unset: {insert: 1}}, true)&lt;/p&gt;

&lt;p&gt;The idea here is to put condition in the query that should never match an existing document. Obviously however, upsert inserts the query data if an insert is performed, thus we need to unset the field used in the query.&lt;/p&gt;

&lt;p&gt;It&apos;s nasty, but it gets the job done. At the very least, it demonstrates the intended outcome I&apos;m looking for.&lt;/p&gt;</comment>
                            <comment id="24910" author="wardrop" created="Tue, 1 Mar 2011 00:14:32 +0000"  >&lt;p&gt;I&apos;m glad you asked. Assuming you want an auto-generated ID, and want to allow identical documents (i.e. documents with the same data, but a different ID), what would you put in the query portion of the update? Leave it blank, e.g.&lt;/p&gt;

&lt;p&gt;db.test.insert(&lt;/p&gt;
{name: &apos;bob&apos;}
&lt;p&gt;)&lt;br/&gt;
db.test.update({}, {$set : &lt;/p&gt;
{name: &apos;bob&apos;}
&lt;p&gt;, $inc: {age: 3}}, true)&lt;/p&gt;

&lt;p&gt;..and the empty query will match all documents, and then select only the first of those to perform the update on. There&apos;s simply no way you can achieve the intended result using an upsert.&lt;/p&gt;</comment>
                            <comment id="24904" author="eliot" created="Tue, 1 Mar 2011 00:00:13 +0000"  >&lt;p&gt;Why wouldn&apos;t you just do an upsert?&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>6.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 1 Mar 2011 00:00:13 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        10 years, 46 weeks, 1 day 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>ramon.fernandez@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            10 years, 46 weeks, 1 day 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>scotthernandez</customfieldvalue>
            <customfieldvalue>wardrop</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrp53b:</customfieldvalue>

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

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

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