<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 04:30: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-32417] Add syntax to express $lookup-$unwind with a single aggregation stage</title>
                <link>https://jira.mongodb.org/browse/SERVER-32417</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;When performing a $lookup to pull in data from single document in another collection the result is persisted as an array (a single element array). A subsequent $unwind is often necessary to make working with this array easier.&lt;/p&gt;

&lt;p&gt;It would be good if $lookup had a switch that allowed it to automatically do this unwind if a single result is detected.&lt;/p&gt;</description>
                <environment></environment>
        <key id="474615">SERVER-32417</key>
            <summary>Add syntax to express $lookup-$unwind with a single aggregation stage</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="3">Duplicate</resolution>
                                        <assignee username="backlog-server-query">Backlog - Query Team</assignee>
                                    <reporter username="aharris">Andrew Harris</reporter>
                        <labels>
                    </labels>
                <created>Wed, 20 Dec 2017 08:18:46 +0000</created>
                <updated>Tue, 6 Dec 2022 03:43:22 +0000</updated>
                            <resolved>Fri, 5 Jan 2018 15:56:43 +0000</resolved>
                                                                    <component>Aggregation Framework</component>
                                        <votes>0</votes>
                                    <watches>7</watches>
                                                                                                                <comments>
                            <comment id="1761118" author="asya" created="Thu, 28 Dec 2017 22:20:45 +0000"  >&lt;blockquote&gt;&lt;p&gt;if $lookup had a switch that allowed it to automatically do this unwind if a single result is detected&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;this means that you would need to always check whether the result is a singleton non-array or an array of multiple elements - that seems &lt;b&gt;much&lt;/b&gt; more user-unfriendly.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=aharris&quot; class=&quot;user-hover&quot; rel=&quot;aharris&quot;&gt;aharris&lt;/a&gt; I&apos;m inclined to close this as WAD or duplicate of $lookupOne request unless you have some additional clarification of this use case.&lt;/p&gt;</comment>
                            <comment id="1758153" author="asya" created="Thu, 21 Dec 2017 20:10:07 +0000"  >&lt;p&gt;When you do a $lookup and then $unwind, it already only executes a single stage (see explain).&lt;/p&gt;

&lt;p&gt;Is your request for syntactic sugar to avoid writing two stages?&lt;/p&gt;

&lt;p&gt;In other words, doing {&lt;tt&gt;$lookup:{ }},{$unwind:&amp;lt;as-field&amp;gt;&lt;/tt&gt;} already executes as a single $lookup stage.&lt;/p&gt;</comment>
                            <comment id="1756893" author="charlie.swanson" created="Wed, 20 Dec 2017 16:16:39 +0000"  >&lt;p&gt;Can you explain what the differences are then? I don&apos;t see any differences aside from syntax, which we&apos;d have to workshop a bit either way.&lt;/p&gt;</comment>
                            <comment id="1756859" author="aharris" created="Wed, 20 Dec 2017 15:57:12 +0000"  >&lt;p&gt;It is not quite a duplicate of 22384 as I understand it but yes essentially $lookupOne looks like it is meant to offer what I&apos;m after.&lt;/p&gt;</comment>
                            <comment id="1756851" author="charlie.swanson" created="Wed, 20 Dec 2017 15:53:44 +0000"  >&lt;p&gt;If I&apos;m understanding that correctly, it sounds like this is a duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-22384&quot; title=&quot;Add $lookUpOne to retrieve single Object on result&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-22384&quot;&gt;SERVER-22384&lt;/a&gt;. Would a $lookupOne or &lt;tt&gt;$lookup: {placeInArray: false&lt;/tt&gt;} work for this use case? Such a switch would likely error if it got more than one result from a lookup, unless I&apos;m missing something.&lt;/p&gt;</comment>
                            <comment id="1756823" author="aharris" created="Wed, 20 Dec 2017 15:37:24 +0000"  >&lt;p&gt;This is why I suggested a switch/parameter in the $lookup so that whether the single element array is unwound or not can be based on the application use case.&lt;/p&gt;

&lt;p&gt;If it helps the usual use case we have is a $lookup to a document using the _id of the remote document. It will return only a single result in $lookup but as a single element array. A parameter like &quot;collapseArray:true&quot; perhaps would be useful in this case.&lt;/p&gt;

&lt;p&gt;Does that make it clearer?&lt;/p&gt;

&lt;p&gt;Obviously, if you are expected 1 or more documents to be returned by the $lookup then this collapsing would not be done/possible.&lt;/p&gt;</comment>
                            <comment id="1756811" author="charlie.swanson" created="Wed, 20 Dec 2017 15:26:57 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=aharris&quot; class=&quot;user-hover&quot; rel=&quot;aharris&quot;&gt;aharris&lt;/a&gt; this looks similar to &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-22384&quot; title=&quot;Add $lookUpOne to retrieve single Object on result&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-22384&quot;&gt;SERVER-22384&lt;/a&gt;. Is there a reason you might want it to preserve arrays for some documents, but take out the array if there&apos;s only one? It seems more common to only ever expect one or 0 results. If you ever expect more than one, isn&apos;t it strictly easier if it&apos;s presented as an array, so all later stages/code don&apos;t have to conditionalize on the structure of the document?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="261987">SERVER-22384</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                                        </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>7.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>Wed, 20 Dec 2017 15:26:57 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        6 years, 6 weeks, 6 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>
                            6 years, 6 weeks, 6 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>aharris</customfieldvalue>
            <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>backlog-server-query</customfieldvalue>
            <customfieldvalue>charlie.swanson@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|htmmbj:</customfieldvalue>

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

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

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