<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:53:10 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-150] Javascript closures</title>
                <link>https://jira.mongodb.org/browse/SERVER-150</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;If I&apos;m not misstaken diff should be accessible within the keyf function, due to closures. However, I need to place it within the keyf function for the shell to recognise it. Is this a bug perhaps?&lt;/p&gt;


&lt;p&gt;Result without diff within the keyf function:&lt;br/&gt;
------------------------------------------------------------------------------------------------&lt;br/&gt;
&amp;gt; getThanks(&apos;summaries&apos;, &quot;759df69a-589e-41a2-b316-a6c91a6fe975&quot;)&lt;br/&gt;
Sun Jul 12 17:40:24 JS Error: uncaught exception: &lt;/p&gt;
{&quot;errno&quot; : -3 , &quot;errmsg&quot; : &quot;invoke failed: JS Error: ReferenceError: diff is not defined nofile_b:4&quot; , &quot;ok&quot; : 0}
&lt;p&gt; &lt;/p&gt;


&lt;p&gt;Result with diff within the keyf function:&lt;br/&gt;
------------------------------------------------------------------------------------------------&lt;br/&gt;
&amp;gt; getThanks(&apos;summaries&apos;, &quot;759df69a-589e-41a2-b316-a6c91a6fe975&quot;)&lt;br/&gt;
[&lt;/p&gt;
{&quot;day&quot; : 6 , &quot;month&quot; : 4 , &quot;year&quot; : 2009 , &quot;count&quot; : 0}
&lt;p&gt;,&lt;/p&gt;
{&quot;day&quot; : 1 , &quot;month&quot; : 5 , &quot;year&quot; : 2009 , &quot;count&quot; : 0}
&lt;p&gt;,&lt;/p&gt;
{&quot;day&quot; : 26 , &quot;month&quot; : 5 , &quot;year&quot; : 2009 , &quot;count&quot; : 0}
&lt;p&gt;]&lt;/p&gt;


&lt;p&gt;FUNCTION&lt;br/&gt;
------------------------------------------------------------------------------------------------&lt;br/&gt;
function getThanks(collection, id) {&lt;/p&gt;

&lt;p&gt;    var now = new Date();&lt;br/&gt;
    var diff = 1000 * 60 * 60 * 24 * 30; // inaccessible&lt;/p&gt;

&lt;p&gt;    var res = db.group({&lt;br/&gt;
        ns: collection,&lt;br/&gt;
        // key: &lt;/p&gt;
{description:null}
&lt;p&gt;,&lt;br/&gt;
        keyf: function(a) {&lt;br/&gt;
            var date = a.createdAt;&lt;br/&gt;
            var time = date.getTime();&lt;br/&gt;
            var now = new Date();&lt;br/&gt;
            var diff = 1000 * 60 * 60 * 24 * 30; // accessible&lt;br/&gt;
            // if (now.getTime() - time &amp;gt; diff) &lt;/p&gt;
{
            //     return null;
            // }
&lt;p&gt;            return &lt;/p&gt;
{
                &quot;day&quot;:date.getDate(),
                &quot;month&quot;:date.getMonth(),
                &quot;year&quot;:date.getFullYear()
            }
&lt;p&gt;;&lt;br/&gt;
        },&lt;br/&gt;
        initial: &lt;/p&gt;
{count:0}
&lt;p&gt;,&lt;br/&gt;
        reduce: function(obj, prev)&lt;/p&gt;
{
            // prev.abc.push(obj);
            prev.count + obj.thanks.length;
        }
&lt;p&gt;,&lt;br/&gt;
        cond: &lt;/p&gt;
{&quot;user.$id&quot;: id }
&lt;p&gt;,&lt;br/&gt;
    });&lt;br/&gt;
    // group() returns an array of grouped items.  here, there will be a single&lt;br/&gt;
    // item, as key is {}.&lt;br/&gt;
    return res;&lt;br/&gt;
}&lt;/p&gt;</description>
                <environment>OS X 10.5</environment>
        <key id="10289">SERVER-150</key>
            <summary>Javascript closures</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="backlog-server-platform">DO NOT USE - Backlog - Platform Team</assignee>
                                    <reporter username="sandstrom">sandstrom</reporter>
                        <labels>
                    </labels>
                <created>Sun, 12 Jul 2009 11:49:00 +0000</created>
                <updated>Fri, 17 Feb 2017 19:32:09 +0000</updated>
                            <resolved>Fri, 17 Feb 2017 19:32:09 +0000</resolved>
                                                                    <component>Shell</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1502458" author="jason.carey" created="Fri, 17 Feb 2017 19:32:09 +0000"  >&lt;p&gt;Making this change would be backwards breaking due to the extant server side environment (from sources like system.js) and as such we won&apos;t be able to consider this feature at this time.&lt;/p&gt;</comment>
                            <comment id="18343" author="ioscale" created="Sun, 19 Sep 2010 10:10:28 +0000"  >&lt;p&gt;You should look into the documentation under &quot;scope&quot;.&lt;/p&gt;

&lt;p&gt;db.runCommand(&lt;/p&gt;
 { mapreduce : &amp;lt;collection&amp;gt;,
   map : &amp;lt;mapfunction&amp;gt;,
   reduce : &amp;lt;reducefunction&amp;gt;
   [, query : &amp;lt;query filter object&amp;gt;]
   [, sort : &amp;lt;sort the query.  useful for optimization&amp;gt;]
   [, limit : &amp;lt;number of objects to return from collection&amp;gt;]
   [, out : &amp;lt;output-collection name&amp;gt;]
   [, keeptemp: &amp;lt;true|false&amp;gt;]
   [, finalize : &amp;lt;finalizefunction&amp;gt;]
   [, scope : &amp;lt;object where fields go into javascript global scope &amp;gt;]
   [, verbose : true]
 }
&lt;p&gt;);&lt;/p&gt;


&lt;p&gt;This can probably be used to &quot;mimic&quot; the behaviour you expect. Unfortunately the scope is not copied. I guess this has to do with shipping the functions or so?&lt;/p&gt;</comment>
                            <comment id="10265" author="sandstrom" created="Mon, 13 Jul 2009 13:18:34 +0000"  >&lt;p&gt;It&apos;s not in the documentation. I pasted everything into the shell and ran it.&lt;br/&gt;
I don&apos;t know if it&apos;s possible, but if it is thats something I would find very useful. Would definitely be nice to have, as it works in normal javascript environments.&lt;/p&gt;</comment>
                            <comment id="10262" author="eliot" created="Mon, 13 Jul 2009 10:50:50 +0000"  >&lt;p&gt;That would work if the function was being evaluated locally, but the closure isn&apos;t sent over automatically.&lt;br/&gt;
In babble it used to be, but not in the shell.&lt;br/&gt;
Is there documentation that still says it does?&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4.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>Mon, 13 Jul 2009 10:50:50 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            6 years, 51 weeks, 5 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>backlog-server-platform</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>mira.carey@mongodb.com</customfieldvalue>
            <customfieldvalue>sandstrom</customfieldvalue>
            <customfieldvalue>ioscale</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpxiv:</customfieldvalue>

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

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

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