<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:57:31 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-1608] Retrieving only selected document(s) from within an embedded array</title>
                <link>https://jira.mongodb.org/browse/SERVER-1608</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I am not completely certain, but I believe at present it is not possible to return only selected document(s) from within an embedded array.  For instance;&lt;/p&gt;

&lt;p&gt;document A {&lt;br/&gt;
user_name: example_user,&lt;br/&gt;
remaining_tokens: 40,&lt;br/&gt;
assignees_array[ &lt;/p&gt;
{UUID: 7, next_checkin_time: &amp;lt;some_unix_time&amp;gt;, expires: &amp;lt;some_unix_time&amp;gt;}
&lt;p&gt;, &lt;/p&gt;
{UUID: 1F0, next_checkin_time: &amp;lt;some_unix_time&amp;gt;, expires: &amp;lt;some_unix_time&amp;gt;}
&lt;p&gt;, ...  ]&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;If my program has knowledge of the UUID, and wishes to see &lt;b&gt;only&lt;/b&gt; the sub-document (e.g. If we queried for UUID 7 and then read the next_checkin_time and some other fields).&lt;/p&gt;

&lt;p&gt;db.my_collection.find(&quot;assignees_array.UUID&quot;:&quot;1F0&quot;} =&amp;gt;&lt;/p&gt;
{UUID: 1F0, next_checkin_time: &amp;lt;some_unix_time&amp;gt;, expires: &amp;lt;some_unix_time&amp;gt;}



&lt;p&gt;At present I do not know of a way that it is possible to achieve this, as it returns the entire parent document and all array elements (losing some of the benefit of selecting on the basis of the embedded document&apos;s UUID), so you have to iterate to find the correct item.&lt;/p&gt;</description>
                <environment></environment>
        <key id="12743">SERVER-1608</key>
            <summary>Retrieving only selected document(s) from within an embedded array</summary>
                <type id="6" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14720&amp;avatarType=issuetype">Question</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="eliot">Eliot Horowitz</assignee>
                                    <reporter username="m.savy">m savy</reporter>
                        <labels>
                    </labels>
                <created>Tue, 10 Aug 2010 17:42:25 +0000</created>
                <updated>Wed, 6 Apr 2011 07:20:27 +0000</updated>
                            <resolved>Thu, 17 Feb 2011 20:02:26 +0000</resolved>
                                                                    <component>Querying</component>
                                        <votes>5</votes>
                                    <watches>11</watches>
                                                                                                                <comments>
                            <comment id="24141" author="eliot" created="Thu, 17 Feb 2011 20:02:26 +0000"  >&lt;p&gt;See &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2238&quot; title=&quot;New projection operator $elemMatch&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2238&quot;&gt;&lt;del&gt;SERVER-2238&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="20254" author="sdr984" created="Fri, 12 Nov 2010 15:13:19 +0000"  >&lt;p&gt;I wanted to add to this another request as I&apos;m not sure it was entirely detailed in the above.  We have the same request for embedded documents to only return the array element that was found during the query.  In addition, I think it would be useful that if the element is found the array of another document, that those two are combined together into a return array instead of being pared down arrays in separate documents.  An example is probably best to illustrate what I&apos;m hoping for.&lt;/p&gt;

&lt;p&gt;I have two documents stored looking like this:&lt;/p&gt;

&lt;p&gt;{name:foo  locs:[&lt;br/&gt;
       &lt;/p&gt;
{
               x:3
               y:4
        }
&lt;p&gt;,&lt;br/&gt;
         &lt;/p&gt;
{
               x:3
               y:5
        }
&lt;p&gt;,&lt;/p&gt;
        {
               x:4
               y:5
        }
&lt;p&gt;]},&lt;br/&gt;
{name:bar	locs:[&lt;/p&gt;
        {
               x:3
               y:4
         }
&lt;p&gt;]}&lt;/p&gt;

&lt;p&gt;I would like to perform this query (or something similar) to get the locations matching the value x:3 where I don&apos;t care about any of the parent info:&lt;/p&gt;

&lt;p&gt;db.things.find(&lt;/p&gt;
{locs.x:3}
&lt;p&gt;,&lt;/p&gt;
{locs:1}
&lt;p&gt;)&lt;/p&gt;

&lt;p&gt;Right now I&apos;d get something like this:&lt;/p&gt;


&lt;p&gt;{_id:&quot;abc..123&quot; locs:[&lt;br/&gt;
       &lt;/p&gt;
{
               x:3
               y:4
        }
&lt;p&gt;,&lt;br/&gt;
         &lt;/p&gt;
{
               x:3
               y:5
        }
&lt;p&gt;,&lt;/p&gt;
        {
               x:4
               y:5
        }
&lt;p&gt;]},&lt;br/&gt;
{_id:&quot;abc...456&quot;    locs:[&lt;/p&gt;
        {
               x:3
               y:4
         }
&lt;p&gt;]}&lt;/p&gt;

&lt;p&gt;This has two problems, first the &lt;/p&gt;
{x:4, y:5}
&lt;p&gt; element shows up even though there is not a match in the array, just because there is a document match.  Second the two documents still need to be combined.  It would be great to get a response like this:&lt;/p&gt;

&lt;p&gt;{locs:[&lt;br/&gt;
	 &lt;/p&gt;
{
               x:3
               y:4
        }
&lt;p&gt;,&lt;br/&gt;
         &lt;/p&gt;
{
               x:3
               y:5
        }
&lt;p&gt;,&lt;/p&gt;
        {
               x:3
               y:4
        }
&lt;p&gt;]}&lt;/p&gt;</comment>
                            <comment id="16677" author="m.savy" created="Tue, 10 Aug 2010 18:05:14 +0000"  >&lt;p&gt;Actually, one can exclude the parent document&apos;s other fields by using exclusion &lt;/p&gt;

&lt;p&gt;e.g.&lt;br/&gt;
db.my_collection.find(&quot;assignees_array.UUID&quot;:&quot;1F0&quot;},&lt;/p&gt;
{&quot;assignees_array&quot; : 1}
&lt;p&gt;); &lt;/p&gt;

&lt;p&gt;but the other array elements will still be there, that you aren&apos;t interested in.&lt;/p&gt;

&lt;p&gt;edit: if this was a separate collection versus embedded &lt;span class=&quot;error&quot;&gt;&amp;#91;for assignees array&amp;#93;&lt;/span&gt;, you would lose the atomic update ability, and therefore if a crash occurred between assigning the user and changing the &quot;assigned&quot; counter, there would be db inconsistencies.  &lt;/p&gt;

&lt;p&gt;One could count the assigned tokens manually each time, but this is going to be very inefficient in the situation where you need to check the count on every access.&lt;/p&gt;

&lt;p&gt;edit2: this may be similar &lt;a href=&quot;http://jira.mongodb.org/browse/SERVER-142&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/SERVER-142&lt;/a&gt; ?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="11615">SERVER-828</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>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Fri, 12 Nov 2010 15:13:19 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            13 years, 6 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>eliot</customfieldvalue>
            <customfieldvalue>m.savy</customfieldvalue>
            <customfieldvalue>sdr984</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrphen:</customfieldvalue>

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

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

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