<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:09:43 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-5731] db.eval() for sharding collections</title>
                <link>https://jira.mongodb.org/browse/SERVER-5731</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I see &lt;a href=&quot;http://www.mongodb.org/display/DOCS/Sharding+Limits#ShardingLimits-db.evalDOCS%3AServersideCodeExecution&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.mongodb.org/display/DOCS/Sharding+Limits#ShardingLimits-db.evalDOCS%3AServersideCodeExecution&lt;/a&gt;&lt;br/&gt;
But is it too complicated?&lt;/p&gt;

&lt;p&gt;I can`t use MR for it&lt;/p&gt;</description>
                <environment></environment>
        <key id="37536">SERVER-5731</key>
            <summary>db.eval() for sharding collections</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="azat">Azat Khuzhin</reporter>
                        <labels>
                    </labels>
                <created>Tue, 1 May 2012 14:39:43 +0000</created>
                <updated>Fri, 13 Mar 2015 22:31:48 +0000</updated>
                            <resolved>Sun, 8 Mar 2015 23:08:14 +0000</resolved>
                                                                    <component>JavaScript</component>
                    <component>Sharding</component>
                                        <votes>9</votes>
                                    <watches>11</watches>
                                                                                                                <comments>
                            <comment id="852041" author="ramon.fernandez" created="Fri, 13 Mar 2015 22:31:48 +0000"  >&lt;p&gt;db.eval is deprecated in 3.0&lt;/p&gt;</comment>
                            <comment id="214917" author="azat" created="Fri, 14 Dec 2012 13:06:27 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;When you run something in &quot;db.eval()&quot; this javascript will be executed on server.&lt;br/&gt;
And as Scott commented:&lt;br/&gt;
&amp;gt; There are many technical issues around using javascript in a distributed cluster, yes.&lt;/p&gt;

&lt;p&gt;But when you run something in mongo shell this will be executed in that shell, as client javascript.&lt;br/&gt;
It&apos;s like you run this code from you application server.&lt;/p&gt;

&lt;p&gt;I hope that this explains why you can&apos;t run some javascript in &quot;db.eval()&quot;, that you can run using mongo shell.&lt;/p&gt;</comment>
                            <comment id="214348" author="caleb.jones@disney.com" created="Thu, 13 Dec 2012 21:24:55 +0000"  >&lt;p&gt;Ugh!! Bit by this today.&lt;/p&gt;

&lt;p&gt;My use case: Need to change the shard key for a sharded collection.&lt;/p&gt;

&lt;p&gt;My plan?&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;Copy sharded collection to tmp non-sharded collection (DB can handle the size)&lt;/li&gt;
	&lt;li&gt;migrate the shard key there (i need to do this in my application code since there&apos;s business logic I don&apos;t want to port to javascript)&lt;/li&gt;
	&lt;li&gt;delete data from original sharded collection&lt;/li&gt;
	&lt;li&gt;Copy from tmp non-sharded collection back into original sharded collection&lt;/li&gt;
	&lt;li&gt;Drop tmp non-sharded collection&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;I wrote it all up only to hit this brick wall.&lt;/p&gt;

&lt;p&gt;It seems very awkward that I can do the following in the mongo shell on a sharded collection (2.2.1):&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;   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;mongos&amp;gt; db.getCollection(&quot;myShardedCollection&quot;).find().foreach(function(doc) { db.getCollection(&quot;newNonShardedCollection&quot;).insert(doc)  } )&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;But the following in client drivers (e.g. Java driver):&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;   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;db.eval(&quot;db.getCollection(\&quot;myShardedCollection\&quot;).find().forEach( function(doc) { db.getCollection(\&quot;newNonShardedCollection\&quot;).insert(doc); })&quot;);&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;...results in 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;   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;Error: command failed [$eval]: { &quot;serverUsed&quot; : &quot;host/&amp;lt;IP&amp;gt;:27017&quot; , &quot;errno&quot; : -3.0 , &quot;errmsg&quot; : &quot;invoke failed: JS Error: Error: can&apos;t use sharded collection from db.eval src/mongo/shell/db.js:30&quot; , &quot;ok&quot; : 0.0}&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;My expectation is that if I can do something in the Mongo shell, that I should be able to do it in a client driver. Am I doing something wrong here?&lt;/p&gt;</comment>
                            <comment id="127655" author="nodkz" created="Thu, 7 Jun 2012 04:39:02 +0000"  >&lt;p&gt;I need analog of MySQL syntax &quot;INSERT ... SELECT ...&quot; (&lt;a href=&quot;http://dev.mysql.com/doc/refman/5.0/en/insert-select.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://dev.mysql.com/doc/refman/5.0/en/insert-select.html&lt;/a&gt;) in Mongo with sharded collections. &lt;br/&gt;
This avoid bottleneck in network transfer of the huge amount data between server and application/code.&lt;/p&gt;

&lt;p&gt;My use-case detailed described here &lt;a href=&quot;https://groups.google.com/group/mongodb-user/browse_thread/thread/1d9da32836f0347e/52508dea8b7c0122&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://groups.google.com/group/mongodb-user/browse_thread/thread/1d9da32836f0347e/52508dea8b7c0122&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="115696" author="azat" created="Wed, 2 May 2012 18:50:33 +0000"  >&lt;p&gt;I understand that it can be done using application code.&lt;br/&gt;
But if we are using JS for it, it will decrease IO between mongos, mongod and application.&lt;/p&gt;

&lt;p&gt;BTW how db.eval() works with &quot;abilitiy to distribute collections in a single db&quot; #&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-939&quot; title=&quot;Ability to distribute collections in a single db&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-939&quot;&gt;SERVER-939&lt;/a&gt; ?&lt;/p&gt;</comment>
                            <comment id="115630" author="scotthernandez" created="Wed, 2 May 2012 16:38:52 +0000"  >&lt;p&gt;This is something best done by the application/code not via javascript. The only advantage javascript has is that it runs closer to the data but that can be done with any application running close to the data. In fact javascript may be slower for this than running similar code from another language. There are also many issues with using javascript like in terms of data type support.&lt;/p&gt;

&lt;p&gt;Eval should mostly be used for administrative or one-off scripts where you need things done in the lock, which doesn&apos;t make sense in a sharded system so much.&lt;/p&gt;

&lt;p&gt;I&apos;ll leave this open since many people will ask for it and might have better use-cases &amp;#8211; which I&apos;d guess will require other features. &lt;/p&gt;</comment>
                            <comment id="115623" author="azat" created="Wed, 2 May 2012 16:30:45 +0000"  >&lt;p&gt;I have two collections, for example &quot;foo&quot; and &quot;bar&quot;&lt;br/&gt;
They have common field: &quot;key&quot;&lt;/p&gt;

&lt;p&gt;And I need update some fields from &quot;bar&quot; to &quot;foo&quot; (using &quot;key&quot;), for sorting by it&lt;/p&gt;</comment>
                            <comment id="115136" author="scotthernandez" created="Tue, 1 May 2012 14:49:30 +0000"  >&lt;p&gt;What do you need db.eval() for on a sharded cluster?&lt;/p&gt;

&lt;p&gt;There are many technical issues around using javascript in a distributed cluster, yes.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="93158">SERVER-11076</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>8.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 1 May 2012 14:49:30 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            8 years, 48 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>azat</customfieldvalue>
            <customfieldvalue>caleb.jones@disney.com</customfieldvalue>
            <customfieldvalue>nodkz</customfieldvalue>
            <customfieldvalue>ramon.fernandez@mongodb.com</customfieldvalue>
            <customfieldvalue>scotthernandez</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hro4dr:</customfieldvalue>

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

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

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