[SERVER-14201] Support $not in document match negation Created: 07/Jun/14 Updated: 10/Dec/14 Resolved: 09/Jun/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance, Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Neil Lunn | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
Given the example of a set of documents like this:
Currently if you wanted to find all documents that did not contain the combination of "status": "A" and "type": "C" you would have to resort to JavaScript evaluation.
The aggregation pipeline allows such casting to a projection of a field:
Where the existing $not operator applied it's left side evaluation to the query match negating the whole expression of the query on the right side. Not sure if there is an efficient way to apply this to index values or whether the result would be the same collection scan for all documents not matching the exclusion. The general problem presently being that $not is not allowed as a top level operator here at the moment and cannot reverse the entire query condition as it expects a left side field value. And the JavaScript form for a $where clause is not allowed within an aggregation expression
|
| Comments |
| Comment by Asya Kamsky [ 09/Jun/14 ] | |||||||||||||
|
The requested functionality can be achieved by the $or operator with negation of the equality condition:
| |||||||||||||
| Comment by Stennie Steneker (Inactive) [ 09/Jun/14 ] | |||||||||||||
|
As per the discussion with neillunn on Regards, | |||||||||||||
| Comment by Neil Lunn [ 09/Jun/14 ] | |||||||||||||
|
Then this appears to actually be a bug in the 2.6.1 release where all documents would be returned. | |||||||||||||
| Comment by Asya Kamsky [ 09/Jun/14 ] | |||||||||||||
|
It's "or" of negated condition. Returns everything except the first document, exactly what you "example" would (if you add $where to it). | |||||||||||||
| Comment by Neil Lunn [ 09/Jun/14 ] | |||||||||||||
|
It's not the same logic. The examples as shown would negate the first document from the result as the query asks for the inverse of the documents that contain both status "A" and type "C". A query with $or as shown would not actually negate anything and return all of the results. | |||||||||||||
| Comment by Asya Kamsky [ 08/Jun/14 ] | |||||||||||||
|
Why can't you use $or
|