<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:53:46 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-340] $setOnInsert modifier for upsert</title>
                <link>https://jira.mongodb.org/browse/SERVER-340</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;This will set the fields specified in $setOnInsert:&lt;/p&gt;
{&amp;lt;fields&amp;gt;}
&lt;p&gt; if the update results in an insert. It does nothing if any existing documents are updated.&lt;/p&gt;</description>
                <environment></environment>
        <key id="10706">SERVER-340</key>
            <summary>$setOnInsert modifier for upsert</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</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="alerner">Alberto Lerner</assignee>
                                    <reporter username="gf">gf</reporter>
                        <labels>
                    </labels>
                <created>Wed, 7 Oct 2009 14:42:06 +0000</created>
                <updated>Fri, 7 Mar 2014 00:03:15 +0000</updated>
                            <resolved>Tue, 12 Feb 2013 16:05:47 +0000</resolved>
                                    <version>1.1.1</version>
                                    <fixVersion>2.4.0-rc1</fixVersion>
                                    <component>Write Ops</component>
                                        <votes>65</votes>
                                    <watches>49</watches>
                                                                                                                <comments>
                            <comment id="276661" author="niks@slalom.com" created="Wed, 27 Feb 2013 00:11:02 +0000"  >&lt;p&gt;@Scott Nichol +1&lt;/p&gt;</comment>
                            <comment id="260403" author="auto" created="Thu, 7 Feb 2013 22:07:32 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2013-02-07T21:53:24Z&apos;, u&apos;email&apos;: u&apos;alerner@10gen.com&apos;, u&apos;name&apos;: u&apos;Alberto Lerner&apos;}
&lt;p&gt;Message: &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; $setOnInsert should be a no-op in an update.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/52858af695150e71ca17f06e10c07419d54af42b&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/52858af695150e71ca17f06e10c07419d54af42b&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="254932" author="scotthernandez" created="Thu, 31 Jan 2013 18:57:56 +0000"  >&lt;p&gt;The implementation in 2.3.2 is actually what &quot;$setIfAbsent&quot; should be and not the  correct behavior of $setOnInsert.&lt;/p&gt;</comment>
                            <comment id="213194" author="alerner" created="Wed, 12 Dec 2012 17:00:38 +0000"  >&lt;p&gt;Already discussed documentation needs with Sam. &lt;/p&gt;</comment>
                            <comment id="213189" author="auto" created="Wed, 12 Dec 2012 16:55:08 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-12-12T16:46:47Z&apos;, u&apos;email&apos;: u&apos;alerner@10gen.com&apos;, u&apos;name&apos;: u&apos;Alberto Lerner&apos;}
&lt;p&gt;Message: &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; Created a $setOnInsert update operator.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/ac3f20c6dcb8aeaa9ae7182816ab1dc4f15619f5&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/ac3f20c6dcb8aeaa9ae7182816ab1dc4f15619f5&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="165116" author="cuppett" created="Mon, 17 Sep 2012 18:01:29 +0000"  >&lt;p&gt;That&apos;s why I believe setIfAbsent is a better solution.&lt;/p&gt;
</comment>
                            <comment id="165004" author="polidore" created="Mon, 17 Sep 2012 15:06:34 +0000"  >&lt;p&gt;Wait, if you do an upsert and put the _id in the query, it will set the id on the &quot;upserted&quot; document to that which you searched.&lt;/p&gt;</comment>
                            <comment id="164963" author="polidore" created="Mon, 17 Sep 2012 13:12:40 +0000"  >&lt;p&gt;This feature is valuable. Any chance of getting implemented?&lt;/p&gt;</comment>
                            <comment id="161246" author="cuppett" created="Thu, 6 Sep 2012 18:26:00 +0000"  >&lt;p&gt;I have effectively implemented a variant of this feature as $setIfAbsent in pull request #298 (&lt;a href=&quot;https://github.com/mongodb/mongo/pull/298&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/pull/298&lt;/a&gt;).  It appears to satisfy the use case.&lt;/p&gt;</comment>
                            <comment id="113157" author="snichol" created="Tue, 24 Apr 2012 15:40:40 +0000"  >&lt;p&gt;I am one day into my first MongoDB project and already have a definite need for this capability.  It is disconcerting that this has been open since 2009 when it is so useful.&lt;/p&gt;</comment>
                            <comment id="108011" author="glenn" created="Mon, 9 Apr 2012 20:18:20 +0000"  >&lt;p&gt;Rather than &quot;$setOnInsert&quot;, this should be &quot;$onInsert&quot;.  For example,&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;insert({name: &apos;Glenn&apos;}, {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    $onInsert: {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        $set: {x: 1},&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        $pushAll: {y: [1,2,3]}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}, true);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;This allows using the same code to generate change lists, eg.:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;function update_access_counter()&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    return {$set: {last_date: new Date()}, $inc: {uses: 1}}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;coll.update({_id: 1}, update_access_counter());&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;coll.update({name: &apos;Glenn&apos;}, {$onInsert: update_access_counter()}, true);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;They can share code much more easily, since you don&apos;t need separate code to generate &lt;/p&gt;
{last_date: new Date(), uses: 1}
&lt;p&gt; in the second case.&lt;/p&gt;</comment>
                            <comment id="87177" author="babsher" created="Fri, 10 Feb 2012 05:44:06 +0000"  >&lt;p&gt;I think that there is enough of a need that this should be done now, whether there is a patch or not.&lt;/p&gt;</comment>
                            <comment id="86212" author="pheinze" created="Tue, 7 Feb 2012 19:52:28 +0000"  >&lt;p&gt;If there&apos;s already some code ready for inclusion into trunk this should be added asap. I don&apos;t feel that this new operator would clutter the code more than it&apos;s already and if so I&apos;m not sure if this added functionality isn&apos;t worth it.&lt;br/&gt;
For the naming I don&apos;t feel that $setDef expresses what the operator does maybe even add may be too unspecific, further I don&apos;t think that something like $ifnotset would be too long as operator name. But anyway as long as the documentation make clear what the operator is for it can be named whatever the devs like as long as this will make it into core soon &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;Additionally as no refactoring of the current implementation happened for over a year, i don&apos;t feel that a refactoring (which seems not to happen in the very near future) should block the implementation of new operators, which are quite much wanted from the community.&lt;/p&gt;</comment>
                            <comment id="82533" author="remonvv" created="Thu, 26 Jan 2012 15:36:41 +0000"  >&lt;p&gt;By the way, I&apos;m not that fond of $setDef. Although having shorter operator names is generally better this isn&apos;t a very clear name. $addField for example is more clear perhaps although I&apos;m sure other suggestions are viable as well.&lt;/p&gt;</comment>
                            <comment id="82532" author="remonvv" created="Thu, 26 Jan 2012 15:31:38 +0000"  >&lt;p&gt;I&apos;ll ask just to be sure; this addition would allow for upserts where the _id field is not of type ObjectID correct? e.g. update(&lt;/p&gt;
{a:1}
&lt;p&gt;, {$setDef:{_id:&quot;myid&quot;}, $set:{b:1}}, true). In fact, it could be argued server generated _id values can be removed completely through this change. The driver can now do this just as it does for insert/save.&lt;/p&gt;</comment>
                            <comment id="78776" author="babsher" created="Tue, 10 Jan 2012 14:51:10 +0000"  >&lt;p&gt;Is this feature going to be able to make it into the next release?&lt;/p&gt;</comment>
                            <comment id="64582" author="mlk" created="Thu, 3 Nov 2011 21:35:51 +0000"  >&lt;p&gt;$setDef is probably best, but I&apos;ll throw in some more options: $addField, $defVal.&lt;/p&gt;</comment>
                            <comment id="64577" author="scotthernandez" created="Thu, 3 Nov 2011 21:17:28 +0000"  >&lt;p&gt;$defaults/initial/onInsert maybe? It would good to allow all operators listed in there.&lt;/p&gt;</comment>
                            <comment id="64574" author="sethml" created="Thu, 3 Nov 2011 21:08:49 +0000"  >&lt;p&gt;The code seems to prefer shorter names.  How about $setDef?&lt;/p&gt;</comment>
                            <comment id="64569" author="mlk" created="Thu, 3 Nov 2011 21:00:21 +0000"  >&lt;p&gt;WRT name. In Python such an method on a dict is called setdefault, maybe mongo could use the same name. It&apos;s not perfect but much better than $iset IMO.&lt;/p&gt;</comment>
                            <comment id="64566" author="sethml" created="Thu, 3 Nov 2011 20:55:13 +0000"  >&lt;p&gt;I needed this functionality, so I implemented it myself, ready for merging for 2.1:&lt;br/&gt;
&amp;nbsp;&amp;nbsp; &lt;a href=&quot;https://github.com/mongodb/mongo/pull/138&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/pull/138&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This supports $iset of _id, as well as other fields.&lt;/p&gt;

&lt;p&gt;I&apos;m not super keen on the name - &quot;$iset&quot; isn&apos;t very clear to me - but I can&apos;t think of anything I like better offhand.  $new?  $setOpt?  Yuck.&lt;/p&gt;

&lt;p&gt;Can this go in for 2.1?  I realize from &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1534&quot; title=&quot;$min, $max field update operators&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1534&quot;&gt;&lt;del&gt;SERVER-1534&lt;/del&gt;&lt;/a&gt;, the claim:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;  Eliot Horowitz added a comment - Jan 30 2011 05:56:58 AM UTC&lt;br/&gt;
  We&apos;re probably not going to add any more operators until we clean some of that code up.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;...but I think that&apos;s short-sighted.  I agree (after working with it) that this code desperately needs clean-up.  However, adding new modifiers doesn&apos;t make the code much more complex, those new modifiers would need to be supported after a clean-up anyway.&lt;/p&gt;</comment>
                            <comment id="63622" author="mongodevuser" created="Sun, 30 Oct 2011 22:27:36 +0000"  >&lt;p&gt;The $iset should support the definition of the _id value, so that custom ids can be used when an insert is made on an upsert (&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-4175&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/SERVER-4175&lt;/a&gt;).&lt;/p&gt;</comment>
                            <comment id="21137" author="remonvv" created="Tue, 7 Dec 2010 14:30:33 +0000"  >&lt;p&gt;Voted, assuming Torsten&apos;s suggestion is taken into account so that the update is applied on the created document (and specifically the $add-ed fields).&lt;/p&gt;</comment>
                            <comment id="19995" author="rithish" created="Wed, 3 Nov 2010 09:13:32 +0000"  >&lt;p&gt;This issue is still marked as open. Any timeline for this to come into production?&lt;/p&gt;</comment>
                            <comment id="15103" author="eliot" created="Sat, 26 Jun 2010 12:22:29 +0000"  >&lt;p&gt;Yes - something like that.&lt;/p&gt;

&lt;p&gt;You can fork and commit on github.&lt;br/&gt;
This with a bunch of tests should do it.&lt;/p&gt;

&lt;p&gt;Might be another case, but tests would show quickly&lt;/p&gt;</comment>
                            <comment id="15102" author="tcurdt" created="Sat, 26 Jun 2010 04:52:35 +0000"  >&lt;p&gt;Shouldn&apos;t this be something along the lines of...&lt;/p&gt;


&lt;p&gt;diff --git a/db/update.cpp b/db/update.cpp&lt;br/&gt;
index a943752..4527875 100644&lt;br/&gt;
&amp;#8212; a/db/update.cpp&lt;br/&gt;
+++ b/db/update.cpp&lt;br/&gt;
@@ -29,7 +29,7 @@&lt;/p&gt;

&lt;p&gt; namespace mongo {&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;const char* Mod::modNames[] = { &quot;$inc&quot;, &quot;$set&quot;, &quot;$push&quot;, &quot;$pushAll&quot;, &quot;$pull&quot;, &quot;$pullAll&quot; , &quot;$pop&quot;, &quot;$unset&quot; ,&lt;br/&gt;
+    const char* Mod::modNames[] = 
{ &quot;$inc&quot;, &quot;$set&quot;, &quot;$add&quot;, &quot;$push&quot;, &quot;$pushAll&quot;, &quot;$pull&quot;, &quot;$pullAll&quot; , &quot;$pop&quot;, &quot;$unset&quot; ,
                                     &quot;$bitand&quot; , &quot;$bitor&quot; , &quot;$bit&quot; , &quot;$addToSet&quot; }
&lt;p&gt;;&lt;br/&gt;
     unsigned Mod::modNamesNum = sizeof(Mod::modNames)/sizeof(char*);&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;@@ -94,6 +94,14 @@ namespace mongo &lt;/p&gt;
{
             break;
         }

&lt;p&gt;+        case ADD: {&lt;br/&gt;
+            if (in.type() == Undefined) &lt;/p&gt;
{
+                _checkForAppending( elt );
+                b.appendAs( elt , shortFieldName );                
+            }
&lt;p&gt;+            break;&lt;br/&gt;
+        }&lt;br/&gt;
+&lt;br/&gt;
         case UNSET: {&lt;br/&gt;
             appendUnset( b );&lt;br/&gt;
             break;&lt;br/&gt;
@@ -342,6 +350,10 @@ namespace mongo {&lt;br/&gt;
                 mss-&amp;gt;amIInPlacePossible( m.elt.type() == e.type() &amp;amp;&amp;amp;&lt;br/&gt;
                                          m.elt.valuesize() == e.valuesize() );&lt;br/&gt;
                 break;&lt;br/&gt;
+&lt;br/&gt;
+            case Mod::ADD:&lt;br/&gt;
+                mss-&amp;gt;amIInPlacePossible( m.elt.type() != Undefined );&lt;br/&gt;
+                break;&lt;/p&gt;

&lt;p&gt;             case Mod::PUSH:&lt;br/&gt;
             case Mod::PUSH_ALL:&lt;br/&gt;
@@ -454,6 +466,7 @@ namespace mongo {&lt;br/&gt;
             case Mod::PULL:&lt;br/&gt;
             case Mod::PULL_ALL:&lt;br/&gt;
             case Mod::ADDTOSET:&lt;br/&gt;
+            case Mod::ADD:&lt;br/&gt;
                 // this should have been handled by prepare&lt;br/&gt;
                 break;&lt;/p&gt;


&lt;p&gt;(Sorry, untested as it doesn&apos;t build for me yet)&lt;/p&gt;</comment>
                            <comment id="14839" author="tcurdt" created="Thu, 17 Jun 2010 12:52:05 +0000"  >&lt;p&gt;Would be great to be able to combine these two operations into a single upsert&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;code&amp;#93;&lt;/span&gt;&lt;br/&gt;
 @totals.insert(&lt;/p&gt;
{&apos;_id&apos; =&amp;gt; track_id}, {&lt;br/&gt;
    &apos;first_at&apos; =&amp;gt; time,&lt;br/&gt;
    &apos;last_at&apos; =&amp;gt; time,&lt;br/&gt;
    &quot;#{year}&quot; =&amp;gt; 1,&lt;br/&gt;
  })&lt;br/&gt;
&lt;br/&gt;
  @totals.update({&apos;_id&apos; =&amp;gt; track_id}
&lt;p&gt;, {&lt;br/&gt;
    &apos;$set&apos; =&amp;gt; &lt;/p&gt;
{ &apos;last_at&apos; =&amp;gt; time },&lt;br/&gt;
    &apos;$inc&apos; =&amp;gt; { &quot;#{year}&quot; =&amp;gt; 1 },&lt;br/&gt;
  })&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;code&amp;#93;&lt;/span&gt;&lt;br/&gt;
&lt;br/&gt;
so &quot;first_at&quot; only gets set on the first insert&lt;br/&gt;
&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;code&amp;#93;&lt;/span&gt;&lt;br/&gt;
  @totals.update({&apos;_id&apos; =&amp;gt; track_id}, {&lt;br/&gt;
    &apos;$add&apos; =&amp;gt; { &apos;first_at&apos; =&amp;gt; time },&lt;br/&gt;
    &apos;$set&apos; =&amp;gt; { &apos;last_at&apos; =&amp;gt; time }
&lt;p&gt;,&lt;br/&gt;
    &apos;$inc&apos; =&amp;gt; { &quot;#&lt;/p&gt;
{year}
&lt;p&gt;&quot; =&amp;gt; 1 },&lt;br/&gt;
  }, &lt;/p&gt;
{upsert:true}
&lt;p&gt;)&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;code&amp;#93;&lt;/span&gt;&lt;/p&gt;</comment>
                            <comment id="10958" author="gf" created="Mon, 19 Oct 2009 17:55:19 +0000"  >&lt;p&gt;Good thought! $add - to add indendantly and $addbunch - to add if all of properties doesn&apos;t exist.&lt;/p&gt;</comment>
                            <comment id="10874" author="jmsachs" created="Mon, 12 Oct 2009 18:24:31 +0000"  >&lt;p&gt;suggest clarifying the description... &quot;adds new properties only if it doesn&apos;t exist yet.&quot; Does this mean that each property is added only if that property does not exist, and that this decision is made independently for each key in $add&apos;s value? (that&apos;s what I think you mean) Or that they all get added only if all of them do not exist?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                        <issuelink>
            <issuekey id="43910">SERVER-6399</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is depended on by">
                                        <issuelink>
            <issuekey id="58996">DOCS-875</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="10937">SERVER-453</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="19695">SERVER-3440</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="30118">SERVER-4900</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="65574">CSHARP-684</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="58873">SERVER-7894</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>29.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 12 Oct 2009 18:24:31 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        10 years, 51 weeks, 1 day 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-6399'>SERVER-6399</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, 51 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>alerner</customfieldvalue>
            <customfieldvalue>auto</customfieldvalue>
            <customfieldvalue>polidore</customfieldvalue>
            <customfieldvalue>babsher</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>gf</customfieldvalue>
            <customfieldvalue>glenn</customfieldvalue>
            <customfieldvalue>jmsachs</customfieldvalue>
            <customfieldvalue>mongodevuser</customfieldvalue>
            <customfieldvalue>niks@slalom.com</customfieldvalue>
            <customfieldvalue>pheinze</customfieldvalue>
            <customfieldvalue>remonvv</customfieldvalue>
            <customfieldvalue>rithish</customfieldvalue>
            <customfieldvalue>scotthernandez</customfieldvalue>
            <customfieldvalue>snichol</customfieldvalue>
            <customfieldvalue>mlk</customfieldvalue>
            <customfieldvalue>sethml</customfieldvalue>
            <customfieldvalue>cuppett</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|hrpvlr:</customfieldvalue>

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

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

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