<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:00:16 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-2517] Allow mapReduce to create full documents</title>
                <link>https://jira.mongodb.org/browse/SERVER-2517</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;This is a follow up to a support thread: &lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/7e1f16c81940c24b&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/7e1f16c81940c24b&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please allow mapReduce jobs to optionally return full documents instead of placing the result into the value field.&lt;/p&gt;

&lt;p&gt;The _id of the documents would be the reduction key, but the returned value from reduce (or finalize)  would be required to be a hash. This makes working with a permanent collection generated by a map/reduce job much nicer.&lt;/p&gt;

&lt;p&gt;I suggest that a new out option be added:&lt;/p&gt;

&lt;p&gt;out: &lt;/p&gt;
{document: 1}
</description>
                <environment></environment>
        <key id="14625">SERVER-2517</key>
            <summary>Allow mapReduce to create full documents</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="12300">Won&apos;t Do</resolution>
                                        <assignee username="backlog-server-query">Backlog - Query Team</assignee>
                                    <reporter username="chriseppstein">Chris Eppstein</reporter>
                        <labels>
                    </labels>
                <created>Thu, 10 Feb 2011 03:44:54 +0000</created>
                <updated>Tue, 6 Dec 2022 05:45:28 +0000</updated>
                            <resolved>Fri, 28 Jun 2019 14:55:26 +0000</resolved>
                                                                    <component>MapReduce</component>
                                        <votes>149</votes>
                                    <watches>111</watches>
                                                                                                                <comments>
                            <comment id="2304722" author="asya" created="Fri, 28 Jun 2019 14:55:26 +0000"  >&lt;p&gt;This project was superceded by aggregation pipeline adding ability to merge its output into existing collection, including sharded ones via &lt;a href=&quot;https://docs.mongodb.com/master/reference/operator/aggregation/merge/index.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;stage $merge&lt;/a&gt;.  Closing this ticket.&lt;/p&gt;</comment>
                            <comment id="2130043" author="asya" created="Mon, 28 Jan 2019 23:08:14 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=mark.monroe%40aruplab.com&quot; class=&quot;user-hover&quot; rel=&quot;mark.monroe@aruplab.com&quot;&gt;mark.monroe@aruplab.com&lt;/a&gt; thanks for the response.  My goal is to determine exactly this - what gaps does aggregation have that still prevent someone from switching to it from map-reduce.   We added ability to add to existing collection in aggregation for 4.2 but we are trying to prioritize/schedule other work for it.    The idea in that feature is to allow writing to collection via another aggregation, or regular inserts or any other way, so we wouldn&apos;t recreate the existing problems of map-reduce.&lt;/p&gt;</comment>
                            <comment id="2130009" author="mark.monroe@aruplab.com" created="Mon, 28 Jan 2019 22:42:32 +0000"  >&lt;p&gt;The aggregation framework currently does not allow you to append to an existing collection, rather, you can only replace an existing collection with the entire output of the aggregation. Map-reduce is useful when you want to append to an existing collection. In version 4.2 of MongoDB, it looks like the ability to append to an existing collection via an aggregation will be added. That makes this feature request moot for me, as I will just use aggregation instead of map-reduce.&lt;/p&gt;

&lt;p&gt;When you do append to an existing collection with map-reduce, we want the collection to stay around for a while, and having it create full documents in the &lt;em&gt;value&lt;/em&gt; field is ugly from a data structure point of view. For example, what if documents in that collection are added via a normal insert as well as through map-reduce? It looks weird to have normal inserts put the document in a nested &lt;em&gt;value&lt;/em&gt; field.&lt;/p&gt;</comment>
                            <comment id="2129968" author="asya" created="Mon, 28 Jan 2019 22:15:04 +0000"  >&lt;p&gt;Those of you recently voting on this ticket, can you give some additional insight about what exactly you are doing in map-reduce (and why you have to continue using it rather than moving to aggregation framework which runs natively on the server, allows arbitrary transformation of documents, etc)?&lt;/p&gt;</comment>
                            <comment id="2123946" author="hett" created="Wed, 23 Jan 2019 11:43:03 +0000"  >&lt;p&gt;+ 1&lt;/p&gt;</comment>
                            <comment id="1688496" author="psraon7@gmail.com" created="Wed, 4 Oct 2017 00:18:33 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="1351989" author="shukla2009" created="Tue, 9 Aug 2016 20:29:36 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="1311863" author="mox601" created="Fri, 1 Jul 2016 14:49:58 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="1289228" author="gonzalo.diaz" created="Thu, 9 Jun 2016 14:14:08 +0000"  >&lt;p&gt;+1 !&lt;/p&gt;</comment>
                            <comment id="1058842" author="notrix" created="Tue, 13 Oct 2015 10:56:40 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="1057323" author="dhruvg" created="Sat, 10 Oct 2015 20:44:49 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="990332" author="kestes" created="Tue, 28 Jul 2015 03:31:15 +0000"  >&lt;p&gt;For what it is worth, this is the very first time I used the map-reduce functionality of MongoDB, and I found myself here.&lt;/p&gt;</comment>
                            <comment id="988025" author="unbornchikken" created="Fri, 24 Jul 2015 11:27:51 +0000"  >&lt;p&gt;+100&lt;/p&gt;</comment>
                            <comment id="948813" author="ibeaver" created="Wed, 24 Jun 2015 00:49:20 +0000"  >&lt;p&gt;+1 making this configurable would allow MR jobs to merge documents back into collections that were not originally created by a MR job.&lt;/p&gt;</comment>
                            <comment id="859384" author="vipseixas" created="Fri, 20 Mar 2015 17:45:03 +0000"  >&lt;p&gt;+1&lt;br/&gt;
I am using Spring Data for MongoDB and I have to create a dummy Value class just for holding the values intead of putting them directly in the main document class. &lt;/p&gt;</comment>
                            <comment id="805167" author="kay" created="Thu, 15 Jan 2015 11:06:23 +0000"  >&lt;p&gt;+1 Definitly a must have.&lt;/p&gt;</comment>
                            <comment id="730129" author="jeffwhelpley" created="Tue, 30 Sep 2014 00:36:12 +0000"  >&lt;p&gt;+1 There are so many uses for this functionality if it existed. At a high level, it makes it much easier to synchronize de-normalized data.&lt;/p&gt;</comment>
                            <comment id="685827" author="tubededentifrice" created="Sat, 9 Aug 2014 14:20:39 +0000"  >&lt;p&gt;Can&apos;t believe it can&apos;t be done already... through the finalize function, it would be SO easy...&lt;/p&gt;</comment>
                            <comment id="664966" author="confessin" created="Mon, 21 Jul 2014 07:11:45 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="614978" author="rveloso" created="Tue, 10 Jun 2014 04:10:48 +0000"  >&lt;p&gt;+1 and generally a callback function that will allow to transform both the key and the value&lt;/p&gt;</comment>
                            <comment id="503870" author="rturk" created="Mon, 24 Feb 2014 03:10:09 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="491615" author="kelvin" created="Fri, 31 Jan 2014 18:07:02 +0000"  >&lt;p&gt;This would be a game changer. +1!&lt;/p&gt;</comment>
                            <comment id="465519" author="chekyassine" created="Wed, 4 Dec 2013 16:44:09 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="459822" author="bertrand" created="Thu, 21 Nov 2013 16:35:13 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="446584" author="martin.peranic@neofonie.de" created="Fri, 25 Oct 2013 10:33:11 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="427663" author="tamas" created="Wed, 18 Sep 2013 09:23:51 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="418699" author="arimus" created="Thu, 5 Sep 2013 18:00:01 +0000"  >&lt;p&gt;+1 This would allow the results of a mapReduce to be returned such that they simply appear to be a subset of the original collection.  Seems like a pretty natural expectation when you are using mapReduce in this way, which appears to be fairly common from the looks of this thread.  &lt;/p&gt;

&lt;p&gt;In any case, requiring further mangling/unwrapping to remove the added structure from output records is a bit tedious and requires some additional overhead in processing.  Not adding it in the first place would be ideal. So, +1 for non-wrapped (&quot;flat&quot;) output.&lt;/p&gt;</comment>
                            <comment id="392774" author="viniciusbo" created="Wed, 31 Jul 2013 15:30:54 +0000"  >&lt;p&gt;+1 indeed&lt;/p&gt;</comment>
                            <comment id="388044" author="michaelahlers" created="Wed, 24 Jul 2013 19:37:29 +0000"  >&lt;p&gt;I would like this, too. Keying on _id, and returning the updated document seems a natural way to implement document migration when schemas change. (Unless, of course, someone can offer another strategy.)&lt;/p&gt;</comment>
                            <comment id="381130" author="phad" created="Mon, 15 Jul 2013 10:05:41 +0000"  >&lt;p&gt;+1 This would be very helpful for my application too.&lt;/p&gt;</comment>
                            <comment id="376047" author="danielg" created="Mon, 8 Jul 2013 13:13:52 +0000"  >&lt;p&gt;I need it as well +1&lt;/p&gt;</comment>
                            <comment id="371614" author="istefo" created="Mon, 1 Jul 2013 14:23:40 +0000"  >&lt;p&gt;Definitely a +1.&lt;br/&gt;
Using MapReduce to generate the &quot;public&quot; tables that can be queried efficiently, but manually reformatting the documents is not nice.&lt;/p&gt;</comment>
                            <comment id="367669" author="jappy" created="Tue, 25 Jun 2013 21:25:18 +0000"  >&lt;p&gt;+1 map means map, i.e. output should look like input plus desired transformation. I don&apos;t get why anyone would desire the default behavior of wrapping the desired output in a value block--how is this useful? Why reducers are required I don&apos;t get either. With map reduce one should be able to write simple identity mappers and identity reducers.&lt;/p&gt;</comment>
                            <comment id="339870" author="wshaver" created="Mon, 20 May 2013 16:29:54 +0000"  >&lt;p&gt;+1 for some implementation allowing for more shaping of the output document.&lt;/p&gt;</comment>
                            <comment id="277899" author="tianon" created="Thu, 28 Feb 2013 08:44:40 +0000"  >&lt;p&gt;I think if we&apos;re having some kind of incremental merging behavior, it would be useful to be able to specify things like $addToSet, $unset, and $inc instead of just doing an implicit $set or even a naive straight-up replacement.&lt;/p&gt;

&lt;p&gt;This way, using mapReduce to calculate things like statistics becomes trivial, and will eventually get the automatic added benefit of parallelism (now that we have v8) without then adding another naive loop over the output data structure to push the data back into the original.&lt;/p&gt;

&lt;p&gt;Just my $0.02, for what it&apos;s worth.  I know at my company, we&apos;d be plenty happy with just the option to have flat output, as that would make mapReduce useful to us again for at least some cases.  As it stands now, almost everywhere we have used it in the past or might use it in the future, we write all our tasks in some other language like Perl or Go, even for tasks that really would be much simpler directly in JavaScript if mapReduce could have flat output.&lt;/p&gt;</comment>
                            <comment id="277531" author="bugslayer" created="Wed, 27 Feb 2013 22:14:05 +0000"  >&lt;p&gt;@Reuben Garrett, Actually, trying to accomplish incremental MR with an additional initialize would be devastating to performance, because it would mean that every record in the target collection would have to be processed do determine what reduces against what. IMO, all that is really needed is an option for &quot;flat&quot; output. Implementation is very simple:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;If output is flat, every field from the target collction that isn&apos;t _id is the value (so incremental just merges against the record with the same _id)&lt;/li&gt;
	&lt;li&gt;The output flattens all values.&lt;/li&gt;
	&lt;li&gt;Overwrite only emitted fields. Leave others untouched.&lt;/li&gt;
	&lt;li&gt;The emitted value may not contain _id (reserved, because it would conflict with the mapped _id)&lt;/li&gt;
	&lt;li&gt;The emitted _id behaves as usual&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;As a practical matter you can accomplish basically any output format you like this way without significant impact to incremental runtime. The one exception is that the _id value in the incremental collection must exactly match the _id you emit in the map phase, which I think is fair, expected (at least once you think about it), and a small price to pay for not ruining performance.&lt;/p&gt;

&lt;p&gt;Syntax might be something like:&lt;br/&gt;
out: &lt;/p&gt;
{ reduce: &quot;session_stat&quot;, flat: 1 }</comment>
                            <comment id="277234" author="rubytuesdaydono" created="Wed, 27 Feb 2013 16:31:59 +0000"  >&lt;p&gt;+1 for &quot;finalize&quot; as a place to define document layout (&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=martynovs&quot; class=&quot;user-hover&quot; rel=&quot;martynovs&quot;&gt;martynovs&lt;/a&gt;, &lt;cite&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2517?focusedCommentId=137443&amp;amp;page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-137443&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;supra&lt;/a&gt;&lt;/cite&gt;). &lt;/p&gt;

&lt;p&gt;I also see &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=bugslayer&quot; class=&quot;user-hover&quot; rel=&quot;bugslayer&quot;&gt;bugslayer&lt;/a&gt;&apos;s &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2517?focusedCommentId=274208&amp;amp;page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-274208&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;concern&lt;/a&gt; as legitimate - so consider adding an option for an &quot;initialize&quot; function to transform the documents from their persisted format into the manipulation format preferred by map/reduce. Transform functors are a powerful means to achieve customization without requiring exhaustive implementation effort on the part of the committers. To be sure, their work is far from trivial - what I mean is that we can reap significant value by exposing an API hook and delegating implementation of specific use-cases to the user. &lt;/p&gt;</comment>
                            <comment id="274208" author="bugslayer" created="Sun, 24 Feb 2013 00:00:02 +0000"  >&lt;p&gt;The big use case I see for this is incremental map reduce (out: &lt;/p&gt;
{ reduce: &quot;session_stat&quot; }
&lt;p&gt;).&lt;/p&gt;

&lt;p&gt;With an incremental map reduce you &lt;b&gt;can&apos;t&lt;/b&gt; restructure the data after running, because if you do, then it won&apos;t properly reduce new results against the data. This severely limits the usefulness of the reduce output type.&lt;/p&gt;</comment>
                            <comment id="196095" author="b2berry" created="Wed, 21 Nov 2012 21:54:01 +0000"  >&lt;p&gt;+1 I&apos;d fund a few kegs for this feature. My &apos;work around&apos; is to implement custom deserializer(s) at the driver level to map the value to the target object.  Intermediate collections and eval() statements gives me a twitch, but I guess for tiny data sets isn&apos;t a big deal.  &lt;/p&gt;</comment>
                            <comment id="162100" author="m@saffitz.com" created="Sun, 9 Sep 2012 17:14:22 +0000"  >&lt;p&gt;Another +1 for this feature request.  Our use case is similar to Scotty Allen&apos;s.&lt;/p&gt;</comment>
                            <comment id="156587" author="wingmanlars" created="Fri, 24 Aug 2012 21:37:46 +0000"  >&lt;p&gt;+1 for this feature request!&lt;/p&gt;</comment>
                            <comment id="154951" author="arian@beenverified.com" created="Mon, 20 Aug 2012 16:49:48 +0000"  >&lt;p&gt;+1 for this feature request.&lt;/p&gt;

&lt;p&gt;We work with a 3rd party analytics firm. They offer limited support for data stored in MongoDB. One of the limitations is that they can&apos;t (won&apos;t) handle data nested more than one level deep.  Now I have to make a solution to move the m/r output data &quot;up&quot; out of the arbitrary &apos;value&apos; level. Not the end of the world, but it would be cool if I didn&apos;t have to.&lt;/p&gt;</comment>
                            <comment id="150640" author="scottyallen" created="Sun, 5 Aug 2012 23:55:16 +0000"  >&lt;p&gt;We just got bitten by this as well.  We were hoping to use map reduce to setup permanent data warehouse fact tables.  This design choice makes this significantly clunkier.&lt;/p&gt;</comment>
                            <comment id="146716" author="tianon" created="Tue, 24 Jul 2012 17:14:54 +0000"  >&lt;p&gt;If you&apos;re going to use eval() to flatten, you definitely want to make sure you&apos;re well familiar with the following documentation regarding locking: &lt;a href=&quot;http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Writelocks&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Writelocks&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="146410" author="icambron" created="Tue, 24 Jul 2012 01:53:19 +0000"  >&lt;p&gt;Thanks Doug. That&apos;s the solution I settled on too. It feels pretty silly though, so I was hoping someone had something better. I will try moving it into an eval() call, though.&lt;/p&gt;</comment>
                            <comment id="146409" author="crudson" created="Tue, 24 Jul 2012 01:48:45 +0000"  >&lt;p&gt;Isaac, you have to foreach the MR target collection, then flatten and save to another collection (or update back to the same collection).&lt;/p&gt;

&lt;p&gt;For large number of map reduce output documents, recommend to do this as an eval() rather than through a client driver for performance reasons.&lt;/p&gt;</comment>
                            <comment id="146395" author="icambron" created="Tue, 24 Jul 2012 00:28:36 +0000"  >&lt;p&gt;Given that explicitly saving to another collection in finalize no longer works (as noted above), what&apos;s the best way to work around this? How are people flattening the values?&lt;/p&gt;</comment>
                            <comment id="145197" author="cvincent" created="Fri, 20 Jul 2012 05:27:07 +0000"  >&lt;p&gt;+1, would be extremely useful!&lt;/p&gt;</comment>
                            <comment id="137443" author="martynovs" created="Thu, 28 Jun 2012 09:26:09 +0000"  >&lt;p&gt;+1 for &quot;finalize&quot; as a place to define document layout&lt;/p&gt;</comment>
                            <comment id="133451" author="ihgreenman" created="Fri, 15 Jun 2012 20:14:22 +0000"  >&lt;p&gt;+1 as well, and I particularly like the idea of using &quot;finalize&quot; for this. I&apos;m interested in using this in much the same way as the other reporters &amp;#8211; to maintain a permanent M/R collection.&lt;/p&gt;</comment>
                            <comment id="120054" author="majidmx" created="Wed, 16 May 2012 14:14:45 +0000"  >&lt;p&gt;+1 for the feature.&lt;br/&gt;
If you want the aggregated results to be stored in a separate collection and be used later on, and also incrementally update values, a flattened key/value document would be a lot nicer and convenient to be used.&lt;/p&gt;</comment>
                            <comment id="113223" author="penn.taylor" created="Tue, 24 Apr 2012 17:12:30 +0000"  >&lt;p&gt;&amp;#43;1 for this feature addition. We use mongo for object persistence in a C++ context, and the current output of MapReduce requires us to manually flatten the objects before we can access them in a meaningful way. I shouldn&apos;t have to know whether the document I&apos;m using to populate an object is a first-gen document or the output of a MapReduce job. As things stand, we push the output of MapReduce into a special &quot;MROUT&quot; collection, then iterate through the documents in that collection, flatten them, and move them into the main collection. That seems like unnecessary work.&lt;/p&gt;</comment>
                            <comment id="63428" author="fuwjax" created="Fri, 28 Oct 2011 20:43:58 +0000"  >&lt;p&gt;Perhaps instead of adding another option, this behavior could be built into the finalize function directly. As I understand finalize, it&apos;s currently used to transform the final value into another value, and as such the &quot;default&quot; implementation of finalize would be the following:&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(key, value) {&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 value;&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;}&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;What if finalize instead returned the document that should be stored in the permanent collection? In other words, the &quot;default&quot; implementation would be the following:&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(key, value) {&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 {_id: key, value: value};&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;}&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;The documentation seems to suggest that finalize is useful in only a handful of situations. Perhaps this solution would both enhance the usefulness of an existing feature and be relatively low impact, especially given that the required change to replicate the current behavior is straightforward.&lt;/p&gt;</comment>
                            <comment id="58545" author="flori" created="Wed, 5 Oct 2011 04:49:55 +0000"  >&lt;p&gt;I want to use mapreduce to get some aggregated data from one collection into an existing old one (with &lt;/p&gt;
{ reduce : &quot;oldExistingCollection&quot; }
&lt;p&gt;). Without this feature it isn&apos;t possible in a clean way because the structure of the object in the old existing collection is of course already in use.&lt;/p&gt;

&lt;p&gt;At a first step it would help already to be able to change the &quot;value&quot; name to something other.&lt;/p&gt;</comment>
                            <comment id="53098" author="crudson" created="Thu, 8 Sep 2011 22:04:59 +0000"  >&lt;p&gt;+1 for this. I have quite a few MR jobs that now forEach the target collection to flatten objects. For hundreds of millions of documents it&apos;s just a lot of extra work, and db size grows as the output collection is effectively duplicated.&lt;/p&gt;

&lt;p&gt;Indexes are also simplified when at the top level rather than nested in &apos;value&apos;.&lt;/p&gt;

&lt;p&gt;(approach to save in finalize() is no longer valid as latest mongo doesn&apos;t expose db object to finalize, at least the last time I tried it)&lt;/p&gt;</comment>
                            <comment id="51729" author="redbeard0531" created="Wed, 31 Aug 2011 14:30:36 +0000"  >&lt;p&gt;Related stackoverflow question: &lt;a href=&quot;http://stackoverflow.com/questions/7257989/in-mongodb-mapreduce-how-can-i-flatten-the-values-object/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://stackoverflow.com/questions/7257989/in-mongodb-mapreduce-how-can-i-flatten-the-values-object/&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="28560" author="breakbild" created="Sat, 9 Apr 2011 22:51:55 +0000"  >&lt;p&gt;I think this option is the only way I can start using my mapreduce collections as &quot;regular&quot; collections. &lt;/p&gt;

&lt;p&gt;In my case I want to prepare an exported/imported collection to be used in my application. I transform/complete the imported collection using mapreduce (e.g. to rename fields or add default values). The problem is that the result ends up in &quot;value&quot; field and there is no way I can work around this. Unless I structure my regular collections to be available under value. &lt;/p&gt;

&lt;p&gt;Data transformations through mr are nice, but not usable as new sources this way...&lt;/p&gt;</comment>
                            <comment id="25457" author="markembling" created="Mon, 7 Mar 2011 21:45:10 +0000"  >&lt;p&gt;I would also like to throw in my +1 for this, and for the same reason Micah describes: working with permanent MR-generated collections. In my case, this is particularly the case for MR runs which roll up or otherwise aggregate data according to various criteria - I currently end up with weird documents a bit like this (simplified for example purposes):&lt;/p&gt;

&lt;p&gt;{ &quot;_id&quot;: &lt;/p&gt;
{ &quot;date&quot;: /* a date */, &quot;sensor&quot;: /* a number  */  }
&lt;p&gt;, &quot;value&quot;: &lt;/p&gt;
{ &quot;reading&quot;: /* a number */ }
&lt;p&gt; }&lt;/p&gt;

&lt;p&gt;As you can see, the relevent data is split across the &quot;_id&quot; and the &quot;value&quot; hashes, and that&apos;s just weird. I&apos;d prefer to be able to create a document where the important three fields are at the top level. I couldn&apos;t really care less about what &quot;_id&quot; then contained (just an auto-generated ObjectID would be fine, as in other collections...).&lt;/p&gt;

&lt;p&gt;At present, I&apos;m putting up with working with the documents as they come above, and currently looking into using a save-in-finalize() approach like Micah has talked about. Neither solution is as smooth as I&apos;d like if I&apos;m honest. I think this feature would smooth off this slightly confusing area perfectly.&lt;/p&gt;</comment>
                            <comment id="23945" author="micahwedemeyer" created="Tue, 15 Feb 2011 19:16:51 +0000"  >&lt;p&gt;+1&lt;/p&gt;

&lt;p&gt;I agree this would be nice for exactly the reason specified: working with permanent MR-generated collections.&lt;/p&gt;

&lt;p&gt;Currently, the way I handle this is by calling db.my_other_collection.save(value) in the finalize() function. It works, but feels very clunky, and it prevents me from using the &apos;out&apos; parameter as intended.&lt;/p&gt;</comment>
                            <comment id="23588" author="chriseppstein" created="Thu, 10 Feb 2011 19:00:28 +0000"  >&lt;p&gt;It&apos;s a polish feature, IMO. I&apos;ve been very satisfied with the very smooth and polished interactions I&apos;ve had with mongo, and this aspect stands out as very awkward. It&apos;s not like I can&apos;t live with it, it&apos;s just that given all the recent developments regarding mapreduce I feel this feature rounds out that feature set.&lt;/p&gt;

&lt;p&gt;Functionally, having documents formatted this way makes it much easier for me to integrate it with my language bindings (Mongoid in Ruby) and smooths out the data access in the application code.&lt;/p&gt;</comment>
                            <comment id="23536" author="eliot" created="Thu, 10 Feb 2011 05:48:27 +0000"  >&lt;p&gt;Why do you need them in a different format?&lt;br/&gt;
Functionally it shouldn&apos;t be different&lt;/p&gt;

&lt;p&gt;This feature by itself isn&apos;t the problem.&lt;br/&gt;
Any new feature we add, we need to make sure there is enough usage and that its the right way to think about the problem.&lt;/p&gt;</comment>
                            <comment id="23535" author="chriseppstein" created="Thu, 10 Feb 2011 05:40:57 +0000"  >&lt;p&gt;It would be great if you could explain why you&apos;re hesitant to add this feature. Without it, I have to generate to a temp collection (that is no longer temporary and I have to now manually clean up) and then manually iterate over my results and insert them into another collection as a proper document. It&apos;s a bunch of unnecessary busy work.&lt;/p&gt;</comment>
                            <comment id="23521" author="eliot" created="Thu, 10 Feb 2011 04:28:13 +0000"  >&lt;p&gt;Dont&apos; want to add more options unless there is a general consensus that is needed.&lt;br/&gt;
Will see what happens to this ticket.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="11811">SERVER-1031</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="12304">SERVER-1336</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="727512">SERVER-40429</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>63.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_12751" key="com.atlassian.jira.plugin.system.customfieldtypes:multiselect">
                        <customfieldname>Assigned Teams</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="25143"><![CDATA[Query]]></customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Thu, 10 Feb 2011 04:28:13 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        4 years, 32 weeks, 5 days 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>alexander.golin@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            4 years, 32 weeks, 5 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>Hett</customfieldvalue>
            <customfieldvalue>arian@beenverified.com</customfieldvalue>
            <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>backlog-server-query</customfieldvalue>
            <customfieldvalue>bertrand</customfieldvalue>
            <customfieldvalue>b2berry</customfieldvalue>
            <customfieldvalue>chriseppstein</customfieldvalue>
            <customfieldvalue>cvincent</customfieldvalue>
            <customfieldvalue>danielg</customfieldvalue>
            <customfieldvalue>arimus</customfieldvalue>
            <customfieldvalue>dhruvg</customfieldvalue>
            <customfieldvalue>crudson</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>flori</customfieldvalue>
            <customfieldvalue>unbornchikken</customfieldvalue>
            <customfieldvalue>gonzalo.diaz</customfieldvalue>
            <customfieldvalue>ibeaver</customfieldvalue>
            <customfieldvalue>ihgreenman</customfieldvalue>
            <customfieldvalue>icambron</customfieldvalue>
            <customfieldvalue>jeffwhelpley</customfieldvalue>
            <customfieldvalue>bugslayer</customfieldvalue>
            <customfieldvalue>kay</customfieldvalue>
            <customfieldvalue>kelvin</customfieldvalue>
            <customfieldvalue>kestes</customfieldvalue>
            <customfieldvalue>wingmanlars</customfieldvalue>
            <customfieldvalue>majidmx</customfieldvalue>
            <customfieldvalue>markembling</customfieldvalue>
            <customfieldvalue>mark.monroe@aruplab.com</customfieldvalue>
            <customfieldvalue>breakbild</customfieldvalue>
            <customfieldvalue>martin.peranic@neofonie.de</customfieldvalue>
            <customfieldvalue>mathias@mongodb.com</customfieldvalue>
            <customfieldvalue>mox601</customfieldvalue>
            <customfieldvalue>micahwedemeyer</customfieldvalue>
            <customfieldvalue>michaelahlers</customfieldvalue>
            <customfieldvalue>fuwjax</customfieldvalue>
            <customfieldvalue>m@saffitz.com</customfieldvalue>
            <customfieldvalue>confessin</customfieldvalue>
            <customfieldvalue>psraon7@gmail.com</customfieldvalue>
            <customfieldvalue>phad</customfieldvalue>
            <customfieldvalue>penn.taylor</customfieldvalue>
            <customfieldvalue>rturk</customfieldvalue>
            <customfieldvalue>shukla2009</customfieldvalue>
            <customfieldvalue>rubytuesdaydono</customfieldvalue>
            <customfieldvalue>rveloso</customfieldvalue>
            <customfieldvalue>jappy</customfieldvalue>
            <customfieldvalue>scottyallen</customfieldvalue>
            <customfieldvalue>martynovs</customfieldvalue>
            <customfieldvalue>istefo</customfieldvalue>
            <customfieldvalue>tamas</customfieldvalue>
            <customfieldvalue>tianon</customfieldvalue>
            <customfieldvalue>notrix</customfieldvalue>
            <customfieldvalue>tubededentifrice</customfieldvalue>
            <customfieldvalue>viniciusbo</customfieldvalue>
            <customfieldvalue>vipseixas</customfieldvalue>
            <customfieldvalue>wshaver</customfieldvalue>
            <customfieldvalue>chekyassine</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrp6mf:</customfieldvalue>

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

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

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