<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:56:41 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>[JAVA-2235] Multiple $match filters in BSON for aggregator</title>
                <link>https://jira.mongodb.org/browse/JAVA-2235</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;I&apos;m running with below aggregation where in match condition will be added depending upon selected filter &lt;br/&gt;
Bson detailsUnwind = unwind(&quot;$details&quot;);&lt;/p&gt;

&lt;p&gt;Bson empIdMatch = new BasicDBObject();&lt;br/&gt;
Bson deptIdMatch = new BasicDBObject();&lt;br/&gt;
Bson gradeMatch = new BasicDBObject();&lt;/p&gt;

&lt;p&gt; empIdMatch =  match(eq(&quot;empId&quot;,1234567)); // mandatory value - empId&lt;br/&gt;
if(deptId != null) // optional value - deptId&lt;br/&gt;
 deptIdMatch =  match(eq(&quot;details.deptId&quot;,20));&lt;br/&gt;
if(grade != null) // optional value - grade&lt;br/&gt;
 gradeMatch =  match(eq(&quot;details.grade&quot;,&quot;L1&quot;));&lt;/p&gt;

&lt;p&gt;List&amp;lt;Bson&amp;gt; pipeline = asList(detailsUnwind,empIdMatch,deptIdMatch,gradeMatch);&lt;/p&gt;

&lt;p&gt;AggregateIterable&amp;lt;Document&amp;gt; aggresult = collection.aggregate(pipeline);&lt;/p&gt;

&lt;p&gt;for (Document documet : aggresult) {&lt;br/&gt;
	Document doc = (Document) documet.get(&quot;details&quot;);&lt;br/&gt;
		if (doc != null) &lt;/p&gt;
{
			System.out.println(&quot;Testing&quot;);
		}
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;If i level is not available, than i&apos;m getting - &lt;br/&gt;
Command failed with error 16435: &apos;exception: A pipeline stage specification object must contain exactly one field.&apos; on server &amp;lt;hostname&amp;gt;:&amp;lt;port&amp;gt;. The full response is &lt;/p&gt;
{ &quot;code&quot; : 16435, &quot;ok&quot; : 0.0, &quot;errmsg&quot; : &quot;exception: A pipeline stage specification object must contain exactly one field.&quot; }

&lt;p&gt;This is what i want to achieve&lt;/p&gt;

&lt;p&gt;Case 1) When both Department and Level details are available&lt;br/&gt;
collection.aggregate(&lt;br/&gt;
       [&lt;br/&gt;
              {$unwind: &apos;$details&apos;},&lt;br/&gt;
              {      $match: &lt;br/&gt;
                           {&apos;empId&apos;: 123456,&lt;br/&gt;
                           &apos;details.deptId&apos; : 20,&lt;br/&gt;
                           &apos;details.grade&apos; : &apos;L1&apos;&lt;br/&gt;
                           }}&lt;br/&gt;
              ]&lt;br/&gt;
       )&lt;/p&gt;

&lt;p&gt;Case 2) When only Grade is available&lt;br/&gt;
collection.aggregate(&lt;br/&gt;
       [&lt;br/&gt;
              {$unwind: &apos;$details&apos;},&lt;br/&gt;
              {      $match: &lt;br/&gt;
                           {&apos;empId&apos;: 123456,&lt;br/&gt;
                           &apos;details.grade&apos; : &apos;L1&apos;&lt;br/&gt;
                           }}&lt;br/&gt;
              ]&lt;br/&gt;
       )&lt;/p&gt;




</description>
                <environment>Java 1.8, Java MongoDB driver v3.2.2, MongoDB 3.0.11</environment>
        <key id="297360">JAVA-2235</key>
            <summary>Multiple $match filters in BSON for aggregator</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</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="-1">Unassigned</assignee>
                                    <reporter username="paddyrec">PRDP</reporter>
                        <labels>
                            <label>driver</label>
                            <label>query</label>
                    </labels>
                <created>Wed, 29 Jun 2016 07:07:48 +0000</created>
                <updated>Wed, 11 Sep 2019 19:13:31 +0000</updated>
                            <resolved>Wed, 29 Jun 2016 12:18:01 +0000</resolved>
                                    <version>3.2.2</version>
                                                    <component>API</component>
                    <component>BSON</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="1309571" author="ross@10gen.com" created="Wed, 29 Jun 2016 12:17:53 +0000"  >&lt;blockquote&gt;
&lt;p&gt; A pipeline stage specification object must contain exactly one field&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;You must only include pipeline stages that actually perform an operation - so you cannot have empty stages.  Do not include empty documents in your pipeline list.&lt;/p&gt;

&lt;p&gt;Just to let you know this project is for Java driver bugs or feature requests.  The best place for questions regarding MongoDB usage or the Java driver specifics is the &lt;a href=&quot;https://groups.google.com/forum/#!forum/mongodb-user&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongodb-user mailing list&lt;/a&gt; or &lt;a href=&quot;http://stackoverflow.com&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;stackoverflow&lt;/a&gt; as you will reach a boarder audience there.  If your business requires an answer from MongoDB within a set time frame then we do offer &lt;a href=&quot;https://www.mongodb.com/products/production-support&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;production support&lt;/a&gt;.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hsn04v:</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>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>