Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SERVER-670 don't allow simple index matching with negating operators

  • Loading branch information...
commit 2bdb76cf6f0652e90ef35c23de35225c3e0b0ef8 1 parent b3f2b01
@astaple astaple authored
View
8 db/matcher.cpp
@@ -209,6 +209,7 @@ namespace mongo {
break;
}
case BSONObj::NE:{
+ haveNeg = true;
shared_ptr< BSONObjBuilder > b( new BSONObjBuilder() );
_builders.push_back( b );
b->appendAs(fe, e.fieldName());
@@ -218,7 +219,10 @@ namespace mongo {
case BSONObj::opALL:
all = true;
case BSONObj::opIN:
+ basics.push_back( ElementMatcher( e , op , fe.embeddedObject(), isNot ) );
+ break;
case BSONObj::NIN:
+ haveNeg = true;
basics.push_back( ElementMatcher( e , op , fe.embeddedObject(), isNot ) );
break;
case BSONObj::opMOD:
@@ -267,7 +271,7 @@ namespace mongo {
/* _jsobj - the query pattern
*/
Matcher::Matcher(const BSONObj &_jsobj, const BSONObj &constrainIndexKey) :
- where(0), jsobj(_jsobj), haveSize(), all(), hasArray(0), haveNot(), _atomic(false), nRegex(0) {
+ where(0), jsobj(_jsobj), haveSize(), all(), hasArray(0), haveNeg(), _atomic(false), nRegex(0) {
BSONObjIterator i(jsobj);
while ( i.more() ) {
@@ -320,7 +324,7 @@ namespace mongo {
isOperator = true;
if ( fn[1] == 'n' && fn[2] == 'o' && fn[3] == 't' && fn[4] == 0 ) {
- haveNot = true;
+ haveNeg = true;
switch( fe.type() ) {
case Object: {
BSONObjIterator k( fe.embeddedObject() );
View
4 db/matcher.h
@@ -122,7 +122,7 @@ namespace mongo {
bool matches(const BSONObj& j);
- bool keyMatch() const { return !all && !haveSize && !hasArray && !haveNot; }
+ bool keyMatch() const { return !all && !haveSize && !hasArray && !haveNeg; }
bool atomic() const { return _atomic; }
@@ -146,7 +146,7 @@ namespace mongo {
bool haveSize;
bool all;
bool hasArray;
- bool haveNot;
+ bool haveNeg;
/* $atomic - if true, a multi document operation (some removes, updates)
should be done atomically. in that case, we do not yield -
View
13 jstests/indexg.js
@@ -0,0 +1,13 @@
+
+f = db.jstests_indexg;
+f.drop();
+f.save( { list: [1, 2] } );
+f.save( { list: [1, 3] } );
+
+doit = function() {
+ assert.eq( 1, f.count( { list: { $in: [1], $ne: 3 } } ) );
+ assert.eq( 1, f.count( { list: { $in: [1], $not:{$in: [3] } } } ) );
+}
+doit();
+f.ensureIndex( { list: 1 } );
+doit();
View
2  mongo.xcodeproj/project.pbxproj
@@ -497,6 +497,7 @@
93BFA0E311330A8C0045D084 /* not2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = not2.js; sourceTree = "<group>"; };
93C38E940FA66622007D6E4A /* basictests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = basictests.cpp; sourceTree = "<group>"; };
93CC40C2113C407A00734218 /* insert1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = insert1.js; sourceTree = "<group>"; };
+ 93CC441A113DE6BA00734218 /* indexg.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = indexg.js; sourceTree = "<group>"; };
93D0C1520EF1D377005253B7 /* jsobjtests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsobjtests.cpp; sourceTree = "<group>"; };
93D0C1FB0EF1E267005253B7 /* namespacetests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = namespacetests.cpp; sourceTree = "<group>"; };
93D5A8921117A1380052C931 /* regex6.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = regex6.js; sourceTree = "<group>"; };
@@ -745,6 +746,7 @@
934BEB9A10DFFA9600178102 /* jstests */ = {
isa = PBXGroup;
children = (
+ 93CC441A113DE6BA00734218 /* indexg.js */,
93CC40C2113C407A00734218 /* insert1.js */,
93BFA0E311330A8C0045D084 /* not2.js */,
93B9FA36112CAC3C0066ECD2 /* shellkillop.js */,
Please sign in to comment.
Something went wrong with that request. Please try again.