From 6c7dc2b0f8831fac6621f125889d873241588b02 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 8 Mar 2010 18:16:53 -0800 Subject: [PATCH] SERVER-322 $nin and regex --- db/matcher.cpp | 11 +++++++++++ jstests/regex5.js | 22 +++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/db/matcher.cpp b/db/matcher.cpp index aded737c60f..8c82d1bc234 100644 --- a/db/matcher.cpp +++ b/db/matcher.cpp @@ -565,6 +565,17 @@ namespace mongo { if ( ret != 1 ) return ret; } + if ( em.myregex.get() ) { + BSONElementSet s; + obj.getFieldsDotted( fieldName, s ); + for( vector::const_iterator i = em.myregex->begin(); i != em.myregex->end(); ++i ) { + for( BSONElementSet::const_iterator j = s.begin(); j != s.end(); ++j ) { + if ( regexMatches( *i, *j ) ) { + return -1; + } + } + } + } return 1; } diff --git a/jstests/regex5.js b/jstests/regex5.js index b72e1ba0859..418752b8aaf 100644 --- a/jstests/regex5.js +++ b/jstests/regex5.js @@ -10,15 +10,19 @@ x = /.*y.*/ doit = function() { -assert.eq( 1 , t.find( { x : a } ).count() , "A" ) -assert.eq( 2 , t.find( { x : x } ).count() , "B" ) -assert.eq( 2 , t.find( { x : { $in: [ x ] } } ).count() , "C" ) // SERVER-322 -assert.eq( 1 , t.find( { x : { $in: [ a, "xyz1" ] } } ).count() , "D" ) // SERVER-322 -assert.eq( 2 , t.find( { x : { $in: [ a, "xyz2" ] } } ).count() , "E" ) // SERVER-322 -assert.eq( 1 , t.find( { x : { $all : [ a , x ] } } ).count() , "F" ) // SERVER-505 -assert.eq( 1 , t.find( { x : { $all : [ a , "abc" ] } } ).count() , "G" ) // SERVER-505 -assert.eq( 0 , t.find( { x : { $all : [ a , "ac" ] } } ).count() , "H" ) // SERVER-505 - + assert.eq( 1 , t.find( { x : a } ).count() , "A" ); + assert.eq( 2 , t.find( { x : x } ).count() , "B" ); + assert.eq( 2 , t.find( { x : { $in: [ x ] } } ).count() , "C" ); // SERVER-322 + assert.eq( 1 , t.find( { x : { $in: [ a, "xyz1" ] } } ).count() , "D" ); // SERVER-322 + assert.eq( 2 , t.find( { x : { $in: [ a, "xyz2" ] } } ).count() , "E" ); // SERVER-322 + assert.eq( 1 , t.find( { x : { $all : [ a , x ] } } ).count() , "F" ); // SERVER-505 + assert.eq( 1 , t.find( { x : { $all : [ a , "abc" ] } } ).count() , "G" ); // SERVER-505 + assert.eq( 0 , t.find( { x : { $all : [ a , "ac" ] } } ).count() , "H" ); // SERVER-505 + assert.eq( 0 , t.find( { x : { $nin: [ x ] } } ).count() , "I" ); // SERVER-322 + assert.eq( 1 , t.find( { x : { $nin: [ a, "xyz1" ] } } ).count() , "J" ); // SERVER-322 + assert.eq( 0 , t.find( { x : { $nin: [ a, "xyz2" ] } } ).count() , "K" ); // SERVER-322 + assert.eq( 2 , t.find( { x : { $not: { $nin: [ x ] } } } ).count() , "L" ); // SERVER-322 + assert.eq( 1 , t.find( { x : { $nin: [ /^a.c/ ] } } ).count() , "M" ) // SERVER-322 } doit();