[SERVER-7261] field range with $not should properly account for type bracketing (query with $not returns different results after adding an index) Created: 04/Oct/12 Updated: 06/Dec/22 Resolved: 12/Jul/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance, Querying |
| Affects Version/s: | 2.2.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Joe Faber | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Done | Votes: | 6 |
| Labels: | query-44-grooming | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
MacOS 10.8.2 |
||
| Issue Links: |
|
||||||||||||||||||||
| Assigned Teams: |
Query
|
||||||||||||||||||||
| Operating System: | OS X | ||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
A query $gt:0 matches all numbers greater than 0. Non numbers do not match. $not:{$gt:0} should match the opposite values of $gt:0, which means all numbers <=0 and all non numbers. I believe the matcher implements this behavior, but the FieldRange constructor employs type bracketing and only matches numbers <= 0. Here is a test:
------------------------------------------------- Without an index, a $not $gt query will return docs where the queried field is missing. Adding an index on that field causes the query to return only documents where the field is present. See example below. $ ./mongo ); ); > db.foo.ensureIndex( {data: 1}); > |
| Comments |
| Comment by David Storch [ 12/Jul/19 ] | ||||||||||||||||||||||
|
It looks like this problem has been fixed:
I only tested the master branch, so I'm not sure exactly when it was fixed, but I'm guessing it's been fixed for some time now. Closing as Gone Away. | ||||||||||||||||||||||
| Comment by Chad Kreimendahl [ 13/Jun/13 ] | ||||||||||||||||||||||
|
Nevermind... it appears that Also, please add that this is a part of all operating systems (unix, windows, osx, etc). We can replicate this on windows 8, windows server 2012, debian, red hat, etc. | ||||||||||||||||||||||
| Comment by Chad Kreimendahl [ 12/Jun/13 ] | ||||||||||||||||||||||
|
We're seeing a very similar issue that's manifesting itself in another unique way. Will file another bug and post it here. Basically, indexed fields operate contrary to documentation. Removing the index makes the field work as intended. | ||||||||||||||||||||||
| Comment by Aaron Staple [ 10/Oct/12 ] | ||||||||||||||||||||||
|
Tentatively assigning to planning bucket a. | ||||||||||||||||||||||
| Comment by Joe Faber [ 05/Oct/12 ] | ||||||||||||||||||||||
|
Downloaded the 2.2.1 RC and it seems to be a problem there as well: $ ./mongo ); ); ); |