<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:56:02 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-1089] $and operator</title>
                <link>https://jira.mongodb.org/browse/SERVER-1089</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;In addition to the $or operator (&lt;a href=&quot;http://jira.mongodb.org/browse/SERVER-205&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/SERVER-205&lt;/a&gt;), I feel there is a need for a $and operator.&lt;br/&gt;
A possible way to write it could be:&lt;/p&gt;

&lt;p&gt;$and: [&lt;/p&gt;
{ &amp;lt;condition1&amp;gt; }
&lt;p&gt;, &lt;/p&gt;
{ &amp;lt;condition2&amp;gt; }
&lt;p&gt;]&lt;/p&gt;

&lt;p&gt;Why it is needed:&lt;br/&gt;
Condition blocks are physically objects. Thus, we cannot have the same property used twice, preventing the use of the same construct/property multiple times in a query.&lt;/p&gt;

&lt;p&gt;Example:&lt;br/&gt;
Suppose I have a collection of user sessions. &lt;br/&gt;
Each session can contain an arbitrary list of key-value pairs, possibly repeated (ie. an identical key can be listed several times in different objects of the list). Additionally, each key value pair has a timestamp, for history purpose.&lt;/p&gt;

&lt;p&gt;A document sample would be&lt;br/&gt;
{&lt;br/&gt;
session_id: 1,&lt;br/&gt;
data: [&lt;br/&gt;
	&lt;/p&gt;
{
		name: &apos;johm&apos;,
		timestamp: 20100504120000
	}
&lt;p&gt;,&lt;br/&gt;
	&lt;/p&gt;
{
		lastname: &apos;doe&apos;,
		timestamp: 20100505120000
	}
&lt;p&gt;,&lt;/p&gt;
	{
		name: &apos;john&apos;,						#the user corrected the initial input
		timestamp: 20100504120100
	}
&lt;p&gt;]&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Now, when I want to query for a session with an user named john, I would need to use $elemMatch, since I can&apos;t match the full element because of the variable timestamp, like below:&lt;/p&gt;

&lt;p&gt;find({&lt;br/&gt;
	data: {$elemMatch: {name: &apos;john&apos;}}&lt;br/&gt;
}); &lt;/p&gt;

&lt;p&gt;Now, I want to look for john doe. But since I can&apos;t repeat the same $elemMatch key in the data condition object, I am stuck.&lt;br/&gt;
The query below would run, but ignore the first condition, since it is being overwritten by the second.&lt;/p&gt;

&lt;p&gt;find({&lt;br/&gt;
	data: {&lt;br/&gt;
		$elemMatch: &lt;/p&gt;
{name: &apos;john&apos;}
&lt;p&gt;,&lt;br/&gt;
		$elemMatch: &lt;/p&gt;
{lastname: &apos;doe&apos;}
&lt;p&gt;	}&lt;br/&gt;
}); &lt;/p&gt;

&lt;p&gt;Possible solution with $and operator: &lt;/p&gt;

&lt;p&gt;find({&lt;br/&gt;
	data: { &lt;br/&gt;
		$and: [&lt;br/&gt;
			{$elemMatch: {name: &apos;john&apos;}},&lt;br/&gt;
			{$elemMatch: {lastname: &apos;doe&apos;}}&lt;br/&gt;
		]&lt;br/&gt;
	}&lt;br/&gt;
}); &lt;/p&gt;</description>
                <environment></environment>
        <key id="11902">SERVER-1089</key>
            <summary>$and operator</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="9">Done</resolution>
                                        <assignee username="aaron">Aaron Staple</assignee>
                                    <reporter username="spin_guillaume">Guillaume Bodi</reporter>
                        <labels>
                    </labels>
                <created>Wed, 5 May 2010 02:05:40 +0000</created>
                <updated>Tue, 12 Jul 2016 00:29:36 +0000</updated>
                            <resolved>Fri, 3 Jun 2011 20:28:18 +0000</resolved>
                                                    <fixVersion>1.9.1</fixVersion>
                                    <component>Querying</component>
                                        <votes>59</votes>
                                    <watches>41</watches>
                                                                                                                <comments>
                            <comment id="38782" author="antoine" created="Wed, 22 Jun 2011 17:52:30 +0000"  >&lt;p&gt;it could also be useful to be able to do ranges in the $in query.&lt;br/&gt;
This would be equivalent to a nested implicit $or on a single key.&lt;br/&gt;
Typically smthing like {prop: {$in: &lt;span class=&quot;error&quot;&gt;&amp;#91;1,2,3&amp;#93;&lt;/span&gt;}} gets converted into single value ranges to look at in index.&lt;br/&gt;
So one could write smthing like:&lt;br/&gt;
db.foo.find({&quot;bar&quot; : {$in: [&lt;/p&gt;
{ &quot;$gte&quot; : 012 , &quot;$lt&quot; : 014}
&lt;p&gt;, &lt;/p&gt;
{ &quot;$gte&quot; :012}
&lt;p&gt;]}})&lt;br/&gt;
Dont know if that is planned or if there would be complications, but would make that kind of query easy and efficient.&lt;/p&gt;</comment>
                            <comment id="36031" author="auto" created="Fri, 3 Jun 2011 20:27:50 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;astaple&apos;, u&apos;name&apos;: u&apos;Aaron&apos;, u&apos;email&apos;: u&apos;aaron@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1089&quot; title=&quot;$and operator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1089&quot;&gt;&lt;del&gt;SERVER-1089&lt;/del&gt;&lt;/a&gt; add some checks for multiple where fields&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/36a3b7aed3470677944ebf75ee8d018ead897d72&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/36a3b7aed3470677944ebf75ee8d018ead897d72&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="36029" author="aaron" created="Fri, 3 Jun 2011 20:21:55 +0000"  >&lt;p&gt;Hi Folks,&lt;/p&gt;

&lt;p&gt;Thanks for letting us know of your interest in nesting $or within $and.&lt;/p&gt;

&lt;p&gt;Support for nesting $or within $and is a nontrivial task, and it requires that we implement &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2585&quot; title=&quot;Allow nested $or operator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2585&quot;&gt;&lt;del&gt;SERVER-2585&lt;/del&gt;&lt;/a&gt; first.&lt;/p&gt;

&lt;p&gt;I&apos;ve filed &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-3192&quot; title=&quot;allow nesting $or within $and&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-3192&quot;&gt;&lt;del&gt;SERVER-3192&lt;/del&gt;&lt;/a&gt; to specifically cover nesting $or within $and, so you can track the issue there.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Aaron&lt;/p&gt;</comment>
                            <comment id="35911" author="datanucleus" created="Fri, 3 Jun 2011 09:17:59 +0000"  >&lt;p&gt;+1 for nested $or/$and combinations.&lt;/p&gt;</comment>
                            <comment id="35909" author="sym3tri" created="Fri, 3 Jun 2011 09:09:30 +0000"  >&lt;p&gt;+1 for Mikael Nousiainen&apos;s comment.&lt;br/&gt;
Nested $or is crucial.&lt;/p&gt;</comment>
                            <comment id="35906" author="rgpublic" created="Fri, 3 Jun 2011 08:16:52 +0000"  >&lt;p&gt;I second this. It&apos;s certainly a step forward that we have $and now. I don&apos;t know why exactly others are voting and watching this issue but for our company the underlying idea was to port applications with flexible web-based search interfaces to MongoDB. This means search interfaces where the users themselves can create logical AND/OR queries by drag&amp;amp;drop. Thus, we don&apos;t know in advance how a query will look like. Without $and we would for instance need to combine different RegEx queries of the same key into one single RegEx etc. A very difficult task - if not impossible. So I had put the project on hold until this was resolved and we were waiting for $and. Now that $and-support is there I wonder what we can actually do with it. If I&apos;m not mistaken, we could now get $and support, but would lose $or support, right? Sigh. One more round of waiting... Should perhaps anyone file another issue on this? Even if $and doesnt seem to help very much at the moment, I&apos;d like to take the chance and say thank you for you work so far. It&apos;s much appreciated.&lt;/p&gt;</comment>
                            <comment id="35900" author="turjakas" created="Fri, 3 Jun 2011 07:14:11 +0000"  >&lt;p&gt;Will support for nesting $or inside $and be added later, possibly before 2.0 release?&lt;/p&gt;

&lt;p&gt;Not allowing nested $or makes $and quite useless for most queries.&lt;/p&gt;</comment>
                            <comment id="35770" author="auto" created="Thu, 2 Jun 2011 17:36:26 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;astaple&apos;, u&apos;name&apos;: u&apos;Aaron&apos;, u&apos;email&apos;: u&apos;aaron@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1089&quot; title=&quot;$and operator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1089&quot;&gt;&lt;del&gt;SERVER-1089&lt;/del&gt;&lt;/a&gt; don&apos;t allow nesting or within and for now, as it will complicate query parsing for index bounds&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/69713ca560d81c127d915b6e7290ca24d99c6ef7&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/69713ca560d81c127d915b6e7290ca24d99c6ef7&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="35769" author="auto" created="Thu, 2 Jun 2011 17:36:24 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;astaple&apos;, u&apos;name&apos;: u&apos;Aaron&apos;, u&apos;email&apos;: u&apos;aaron@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1089&quot; title=&quot;$and operator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1089&quot;&gt;&lt;del&gt;SERVER-1089&lt;/del&gt;&lt;/a&gt; tests for nested and/or cases&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/69ea6ab82248388168c0f747bcb60e1c502f8b75&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/69ea6ab82248388168c0f747bcb60e1c502f8b75&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="35768" author="auto" created="Thu, 2 Jun 2011 17:36:23 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;astaple&apos;, u&apos;name&apos;: u&apos;Aaron&apos;, u&apos;email&apos;: u&apos;aaron@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1089&quot; title=&quot;$and operator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1089&quot;&gt;&lt;del&gt;SERVER-1089&lt;/del&gt;&lt;/a&gt; merge assert codes&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/c2f4f2c8da17af6f4699fe2e34d4405cf600bbea&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/c2f4f2c8da17af6f4699fe2e34d4405cf600bbea&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="35767" author="auto" created="Thu, 2 Jun 2011 17:36:21 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;astaple&apos;, u&apos;name&apos;: u&apos;Aaron&apos;, u&apos;email&apos;: u&apos;aaron@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1089&quot; title=&quot;$and operator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1089&quot;&gt;&lt;del&gt;SERVER-1089&lt;/del&gt;&lt;/a&gt; add and operator&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/635d2a680d46a09969a9616584a272c2cf395201&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/635d2a680d46a09969a9616584a272c2cf395201&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="30037" author="eliot" created="Thu, 28 Apr 2011 05:37:52 +0000"  >&lt;p&gt;Sorry - your&apos;re 2nd one is correct.&lt;br/&gt;
Same as $or&lt;/p&gt;

&lt;p&gt;&amp;gt; db.foo.find( { $or : [ &lt;/p&gt;
{ x : 1 }
&lt;p&gt; , &lt;/p&gt;
{ y : 1 }
&lt;p&gt; ] } )&lt;br/&gt;
&amp;gt; db.foo.find( { $and : [ &lt;/p&gt;
{ x : 1 }
&lt;p&gt; , &lt;/p&gt;
{ y : 1 }
&lt;p&gt; ] } )&lt;/p&gt;
</comment>
                            <comment id="25475" author="bugslayer" created="Tue, 8 Mar 2011 05:28:50 +0000"  >&lt;p&gt;The lack of both $and and nested $or is really ugly. You don&apos;t notice it early on, and then it bites you pretty hard when it&apos;s too late to turn back.&lt;/p&gt;

&lt;p&gt;I should point out though, that both $and and nested $or can be implemented client side fairly trivially (as in, it takes just a couple of hours). If you have any abstraction layer at all, you can easily run the query through a rewrite filter before sending it out. The filter is a piece of cake to write because of the simplicity of the syntax. All you have to do is recursively check the query for $and, $or, and $nor. You let the first $or/$nor through, any others get rewritten with $where (remember to json_encode or you will have just introduced a code injection vulnerability.) $and is more complicated, but can generally be rewritten using $all on any duplicate keys.&lt;/p&gt;</comment>
                            <comment id="24206" author="flavien" created="Fri, 18 Feb 2011 01:49:37 +0000"  >&lt;p&gt;Agreed, both $and and nested $or are a must.&lt;br/&gt;
I created an issue about the nested $or: &lt;a href=&quot;http://jira.mongodb.org/browse/SERVER-2585&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/SERVER-2585&lt;/a&gt;&lt;br/&gt;
Please come vote for it if you want it too.&lt;/p&gt;</comment>
                            <comment id="23895" author="kkouddous" created="Mon, 14 Feb 2011 19:22:32 +0000"  >&lt;p&gt;+1 for both the $and operator and nested $or. This would dramatically simplify our queries given that we have a flexible query UI that we expose to our users (think of the Zendesk search page as a good example). &lt;/p&gt;</comment>
                            <comment id="23383" author="jamieorc" created="Tue, 8 Feb 2011 17:00:03 +0000"  >&lt;p&gt;I&apos;ve also run into a need for this. After trying a large number of unsuccessful permutations, I want $and.&lt;/p&gt;</comment>
                            <comment id="23237" author="fredstluka" created="Mon, 7 Feb 2011 14:07:15 +0000"  >&lt;p&gt;+1 for $and operator and for nested $or.&lt;/p&gt;

&lt;p&gt;Same use case as others:&lt;br/&gt;
&lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_frm/thread/a94ceeb6227929e8&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_frm/thread/a94ceeb6227929e8&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/131b456224b4a3cd&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/131b456224b4a3cd&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I have now had to implement a generic mechanism for converting:&lt;br/&gt;
     (a or b) and (c or d or e or f ...)&lt;br/&gt;
to:&lt;br/&gt;
        (a and c) or (b and c)&lt;br/&gt;
     or (a and d) or (b and d)&lt;br/&gt;
     or (a and e) or (b and e)&lt;br/&gt;
     or (a and f) or (b and f)&lt;br/&gt;
     ...&lt;br/&gt;
Which is tedious, error prone, and probably inefficient.&lt;/p&gt;

&lt;p&gt;Fortunately, I was able to rely on the fact that we currently need only one &lt;br/&gt;
AND clause and that the left side of it is always an OR of exactly 2 clauses.&lt;br/&gt;
That simplified things a lot.&lt;/p&gt;

&lt;p&gt;A generic $and and nestable $or native to Mongo would be a great addition!&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</comment>
                            <comment id="23230" author="rakeeshranjan" created="Mon, 7 Feb 2011 05:57:07 +0000"  >&lt;p&gt;+1 for the $and operator&lt;/p&gt;

&lt;p&gt;Here is my use case: &lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_frm/thread/a94ceeb6227929e8&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_frm/thread/a94ceeb6227929e8&lt;/a&gt;&lt;br/&gt;
(Same as what Ed has mentioned above)&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</comment>
                            <comment id="21903" author="turjakas" created="Wed, 29 Dec 2010 08:35:47 +0000"  >&lt;p&gt;I couldn&apos;t agree more with Ed. My use case is similar, as I create arbitrarily complex queries on large collections programmatically (for searching based on user-defined criteria). Transforming them to another, possibly a lot slower, form would not make any sense, because query execution speed is critical.&lt;/p&gt;</comment>
                            <comment id="21810" author="sym3tri" created="Mon, 27 Dec 2010 03:40:31 +0000"  >&lt;p&gt;Would just like to add my 2 cents and experience. &lt;/p&gt;

&lt;p&gt;I have been trying to implement basic searching functionality into my app. &lt;/p&gt;

&lt;p&gt;Simple cases are fine: &lt;br/&gt;
ie  (A  ||  B) &amp;amp;&amp;amp; (C || D) &lt;br/&gt;
becomes:  &lt;br/&gt;
A &amp;amp;&amp;amp; C || B &amp;amp;&amp;amp; C || A &amp;amp;&amp;amp; D || B &amp;amp;&amp;amp; D &lt;/p&gt;

&lt;p&gt;However the insufficiency of no $and operator becomes quickly apparent when trying to do queries where you have many variables and they are dependent upon each other. Building the query becomes insanely complex.&lt;/p&gt;

&lt;p&gt;ie writing the following logic in a mongo query: &lt;/p&gt;

&lt;p&gt;A &amp;amp;&amp;amp; B &amp;amp;&amp;amp; C &amp;amp;&amp;amp; D || (E &amp;amp;&amp;amp; F) || (G &amp;amp;&amp;amp; H) || (G &amp;amp;&amp;amp; I) || (F &amp;amp;&amp;amp; G &amp;amp;&amp;amp; H) || ((F &amp;amp;&amp;amp; G &amp;amp;&amp;amp; H) || X) ...&lt;/p&gt;

&lt;p&gt;You end up having to copy all the top-level ANDs and duplicate them with each OR block then project out all the different permutations into one giant OR statement. So Implementing even mildly complex searching without the $and operator has been extremely cumbersome. &lt;/p&gt;

&lt;p&gt;I would think that searching through data based on business logic is a popular use case, but currently there is no practical solution. So in terms of querying, I think this is the one crucial missing feature that needs to be addressed. I really hope this gets implemented soon so I can refactor all the messy code I had to write to get around this limitation.&lt;/p&gt;

&lt;p&gt;All that said... aside from the searching, Mongo has been great so far.&lt;/p&gt;</comment>
                            <comment id="18196" author="aaron" created="Wed, 15 Sep 2010 00:34:48 +0000"  >&lt;p&gt;I believe the $elemMatch example above can be done with the current code as follows:&lt;/p&gt;


&lt;p&gt;&amp;gt; db.f.drop()                                                                   &lt;br/&gt;
true&lt;br/&gt;
&amp;gt; db.f.save({ session_id: 1, data: [ &lt;/p&gt;
{ key: &apos;name&apos;, value: &apos;johm&apos;, timestamp: 20100504120000 }
&lt;p&gt;, &lt;/p&gt;
{ key: &apos;lastname&apos;, value: &apos;doe&apos;, timestamp: 20100505120000 }
&lt;p&gt;, &lt;/p&gt;
{ key: &apos;name&apos;, value: &apos;john&apos;, timestamp: 20100504120100 }
&lt;p&gt; ] });&lt;br/&gt;
&amp;gt; db.f.find( { data: { $all: [ { $elemMatch: &lt;/p&gt;
{ key: &apos;name&apos;, value: &apos;john&apos; }
&lt;p&gt; }, { $elemMatch: &lt;/p&gt;
{ key: &apos;lastname&apos;, value: &apos;doe&apos; }
&lt;p&gt; } ] } } );&lt;br/&gt;
{ &quot;_id&quot; : ObjectId(&quot;4c90142f27df0d163acb9a77&quot;), &quot;session_id&quot; : 1, &quot;data&quot; : [&lt;br/&gt;
	&lt;/p&gt;
{
		&quot;key&quot; : &quot;name&quot;,
		&quot;value&quot; : &quot;johm&quot;,
		&quot;timestamp&quot; : 20100504120000
	}
&lt;p&gt;,&lt;br/&gt;
	&lt;/p&gt;
{
		&quot;key&quot; : &quot;lastname&quot;,
		&quot;value&quot; : &quot;doe&quot;,
		&quot;timestamp&quot; : 20100505120000
	}
&lt;p&gt;,&lt;/p&gt;
	{
		&quot;key&quot; : &quot;name&quot;,
		&quot;value&quot; : &quot;john&quot;,
		&quot;timestamp&quot; : 20100504120100
	}
&lt;p&gt;] }&lt;br/&gt;
&amp;gt; db.f.find( { data: { $all: [ { $elemMatch: &lt;/p&gt;
{ key: &apos;name&apos;, value: &apos;john&apos; }
&lt;p&gt; }, { $elemMatch: &lt;/p&gt;
{ key: &apos;lastname&apos;, value: &apos;doerr&apos; }
&lt;p&gt; } ] } } );&lt;br/&gt;
&amp;gt; &lt;/p&gt;</comment>
                            <comment id="16997" author="turjakas" created="Wed, 18 Aug 2010 13:45:46 +0000"  >&lt;p&gt;Can you offer any kind of workaround for the issue I&apos;ve described in the URL I posted above?&lt;br/&gt;
The solution given in the post (converting AND to OR and vice versa) is not an option&lt;br/&gt;
as the queries will become too complex (the one used in the post was just a simplified example)&lt;br/&gt;
and I have to generate them programmatically.&lt;/p&gt;

&lt;p&gt;I just need to get rid of the top-level AND operation.&lt;/p&gt;

&lt;p&gt;I&apos;ve tried to do other kind of transformations such as modifying and to $or: (A &amp;amp;&amp;amp; B) -&amp;gt; !(!A || !B),&lt;br/&gt;
but in this kind of approach I face another limitation of the MongoDB query language&lt;br/&gt;
as you cannot use nested $or operators. Also, it seems that { $not : { $or : [ &lt;/p&gt;
{ ... }
&lt;p&gt; ] } } does not work.&lt;/p&gt;

&lt;p&gt;I&apos;m really desperate with this as we need this kind of functionality in a production system. &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                            <comment id="16972" author="eliot" created="Tue, 17 Aug 2010 13:48:12 +0000"  >&lt;p&gt;1.7.x means its likely to be included in 1.7/1.8&lt;/p&gt;

&lt;p&gt;There is very little chance of it happening for 1.7.0 as there is already a lot of work planned for it.&lt;/p&gt;

&lt;p&gt;Seems likely it&apos;ll happen in 1.7.  For features like this priority is decided heavily by # of votes.&lt;/p&gt;</comment>
                            <comment id="16965" author="turjakas" created="Tue, 17 Aug 2010 08:50:49 +0000"  >&lt;p&gt;I have yet another use case for $and operator:&lt;br/&gt;
&lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/131b456224b4a3cd&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/131b456224b4a3cd&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, the same can be achieved with several transformations, but they make the query unnecessarily complex.&lt;/p&gt;

&lt;p&gt;In my opinion basic $and, $or and $not should all be explicit operators to allow easy construction of any kind of query.&lt;/p&gt;

&lt;p&gt;Could you please comment on the schedule of this feature (what does 1.7.x actually mean here) and&lt;br/&gt;
the possibility of including it in 1.7.0 release already?&lt;/p&gt;</comment>
                            <comment id="15941" author="cpsubrian" created="Mon, 19 Jul 2010 20:46:21 +0000"  >&lt;p&gt;Just popping in to add my support for $and.  My use case is the same as the OP.  I need to combine multiple $elemMatch conditions and the PHP driver is unable to do this without some mechanism to avoid the problem of duplicate keys.  $and would solve this.&lt;/p&gt;</comment>
                            <comment id="15650" author="andy" created="Mon, 12 Jul 2010 14:07:13 +0000"  >&lt;p&gt;A related use case: &lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/e427fe8a2a940eb4&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/e427fe8a2a940eb4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I&apos;ll copy the last example from there:&lt;/p&gt;

&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; db.test.save(&lt;/p&gt;
{&quot;x&quot;: &quot;hello world&quot;}
&lt;p&gt;) &lt;br/&gt;
ObjectId(&apos;4c3b4080a3baa42f5d000000&apos;) &lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; db.test.save(&lt;/p&gt;
{&quot;x&quot;: &quot;mongodb&quot;}
&lt;p&gt;) &lt;br/&gt;
ObjectId(&apos;4c3b4086a3baa42f5d000001&apos;) &lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; db.test.save(&lt;/p&gt;
{&quot;x&quot;: &quot;hello mongo&quot;}
&lt;p&gt;) &lt;br/&gt;
ObjectId(&apos;4c3b408ea3baa42f5d000002&apos;) &lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; list(db.test.find({&quot;x&quot;: {&quot;$all&quot;: &lt;span class=&quot;error&quot;&gt;&amp;#91;re.compile(&amp;quot;mongo&amp;quot;), re.compile(&amp;quot;world&amp;quot;)&amp;#93;&lt;/span&gt;}})) &lt;br/&gt;
[] &lt;/p&gt;

&lt;p&gt;I need the &quot;hello mongo&quot; document instead of [] in the last query. Unfortunately $all does not work with $regex (and maybe any nested operators except for the exact match) as of MongoDB version 1.5.3.&lt;/p&gt;

&lt;p&gt;UPD: looks like I should have had a good cup of coffee before posting the example above. Actually the correct regular expressions would be &quot;hello&quot; and &quot;mongo&quot;, and yes, MongoDB handles them as expected as of 1.5.4.&lt;br/&gt;
However, the original problem was experienced not with the badly formed example but with real code &#8212; an adapter for a DB-agnostic Python API (Docu). The adapter for MongoDB used &lt;/p&gt;
{&apos;$regex&apos;: &apos;foo&apos;}
&lt;p&gt; instead of re.compile(&apos;foo&apos;) with pymongo and this approach failed indeed.&lt;/p&gt;</comment>
                            <comment id="14401" author="arekt" created="Mon, 24 May 2010 12:06:13 +0000"  >&lt;p&gt;Solution for this problem is to use&lt;/p&gt;

&lt;p&gt;$all, $in, $nin operators&lt;/p&gt;

&lt;p&gt;If we want simple AND&lt;/p&gt;

&lt;p&gt;t = Thing.all(&quot;name&quot;=&amp;gt;&lt;/p&gt;
{&quot;$all&quot;=&amp;gt;[&quot;/foo/&quot;,&quot;/bar/&quot;]}
&lt;p&gt;)&lt;/p&gt;

&lt;p&gt;!B AND !C  &amp;lt;=&amp;gt;  !(B OR C)&lt;/p&gt;

&lt;p&gt;t = Thing.all(&quot;name&quot;=&amp;gt;&lt;/p&gt;
{&quot;$nin&quot;=&amp;gt;[&quot;/foo/&quot;,&quot;/bar/&quot;]}
&lt;p&gt;)&lt;/p&gt;

&lt;p&gt;I hope this helps.&lt;/p&gt;</comment>
                            <comment id="14160" author="eliot" created="Tue, 11 May 2010 09:52:28 +0000"  >&lt;p&gt;$and can be usefor for some cases like this&lt;/p&gt;</comment>
                            <comment id="14094" author="spin_guillaume" created="Wed, 5 May 2010 19:45:29 +0000"  >&lt;p&gt;Sorry, I tried to overly simplify my model and introduced a simple solution.&lt;/p&gt;

&lt;p&gt;My actual document structure is&lt;/p&gt;

&lt;p&gt;{&lt;br/&gt;
  session_id: 1,&lt;br/&gt;
  data: [&lt;br/&gt;
    &lt;/p&gt;
{
      key: &apos;name&apos;,
      value: &apos;johm&apos;,
      timestamp: 20100504120000
    }
&lt;p&gt;,&lt;br/&gt;
    &lt;/p&gt;
{
      key: &apos;lastname&apos;,
      value: &apos;doe&apos;,
      timestamp: 20100505120000
    }
&lt;p&gt;,&lt;/p&gt;
    {
      key: &apos;name&apos;,
      value: &apos;john&apos;,
      timestamp: 20100504120100
    }
&lt;p&gt;  ]&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;I organized this key, value structure so that I could index the array of objects for performance.&lt;/p&gt;

&lt;p&gt;In this case, a find query for john doe would turn into &lt;/p&gt;

&lt;p&gt;find({&lt;br/&gt;
  data: {&lt;br/&gt;
    $elemMatch: &lt;/p&gt;
{key: &apos;name&apos;, value: &apos;john&apos;}
&lt;p&gt;,&lt;br/&gt;
    $elemMatch: &lt;/p&gt;
{key: &apos;lastname&apos;, value: &apos;doe&apos;}
&lt;p&gt;  }&lt;br/&gt;
}); &lt;/p&gt;

&lt;p&gt;which only matches the last condition.&lt;/p&gt;

&lt;p&gt;If indexing the array would guarantee performance for querying with any possible &apos;key&apos; in either design (could you confirm this please?), I would go with the first model and my specific problem would indeed be solved.&lt;/p&gt;

&lt;p&gt;However, even beyond my specific modelization (which might very well not be optimal), it is impossible to have a query object involving the same key twice. So I&apos;d like to know more about the rationale behind the &apos;should never need an and&apos; if possible.&lt;/p&gt;</comment>
                            <comment id="14061" author="eliot" created="Wed, 5 May 2010 09:56:29 +0000"  >&lt;p&gt;You should never need an and&lt;br/&gt;
For your case, I believe&lt;/p&gt;

&lt;p&gt;find( &lt;/p&gt;
{ &quot;data.name&quot; : &quot;john&quot; , &quot;data.lastname&quot; : &quot;doe&quot; }
&lt;p&gt; )&lt;br/&gt;
should work.&lt;/p&gt;

&lt;p&gt;if not - please explain &lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                        <issuelink>
            <issuekey id="11692">SERVER-958</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is depended on by">
                                                        </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="17883">SERVER-3192</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="17883">SERVER-3192</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>30.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Wed, 5 May 2010 09:56:29 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        12 years, 35 weeks ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[<s><a href='https://jira.mongodb.org/browse/SERVER-958'>SERVER-958</a></s>]]></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>
                            12 years, 35 weeks 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>aaron</customfieldvalue>
            <customfieldvalue>andy</customfieldvalue>
            <customfieldvalue>datanucleus</customfieldvalue>
            <customfieldvalue>antoine</customfieldvalue>
            <customfieldvalue>arekt</customfieldvalue>
            <customfieldvalue>auto</customfieldvalue>
            <customfieldvalue>cpsubrian</customfieldvalue>
            <customfieldvalue>sym3tri</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>flavien</customfieldvalue>
            <customfieldvalue>fredstluka</customfieldvalue>
            <customfieldvalue>spin_guillaume</customfieldvalue>
            <customfieldvalue>jamieorc</customfieldvalue>
            <customfieldvalue>bugslayer</customfieldvalue>
            <customfieldvalue>kkouddous</customfieldvalue>
            <customfieldvalue>turjakas</customfieldvalue>
            <customfieldvalue>rakeeshranjan</customfieldvalue>
            <customfieldvalue>rgpublic</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpmqv:</customfieldvalue>

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

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

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