summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-04-06 14:11:32 -0400
committerAaron <aaron@10gen.com>2009-04-06 14:11:32 -0400
commitbf07afef73f75c126c86bc185008eff62e981d38 (patch)
tree5620d4fc0ce7cde1d0cd938af1f4138ed3d40bc3
parent0b73b8d3253547d1ae4937020a8ae196b040b770 (diff)
downloadmongo-bf07afef73f75c126c86bc185008eff62e981d38.tar.gz
back out KeyValJsMatcher, until we can fix it to handle multikey arrays correctly
-rw-r--r--db/clientcursor.h2
-rw-r--r--db/dbhelpers.cpp6
-rw-r--r--db/matcher.cpp38
-rw-r--r--db/matcher.h20
-rw-r--r--db/query.cpp34
-rw-r--r--jstests/multi.js6
-rw-r--r--mongo.xcodeproj/project.pbxproj2
7 files changed, 58 insertions, 50 deletions
diff --git a/db/clientcursor.h b/db/clientcursor.h
index da3d601f68c..29890b27220 100644
--- a/db/clientcursor.h
+++ b/db/clientcursor.h
@@ -44,7 +44,7 @@ namespace mongo {
~ClientCursor();
const CursorId cursorid;
string ns;
- auto_ptr<KeyValJSMatcher> matcher;
+ auto_ptr<JSMatcher> matcher;
auto_ptr<Cursor> c;
int pos; /* # objects into the cursor so far */
DiskLoc lastLoc() const {
diff --git a/db/dbhelpers.cpp b/db/dbhelpers.cpp
index b2a8a951b6b..7f8f57671ec 100644
--- a/db/dbhelpers.cpp
+++ b/db/dbhelpers.cpp
@@ -60,14 +60,14 @@ namespace mongo {
if ( !c_->ok() )
setComplete();
else
- matcher_.reset( new KeyValJSMatcher( qp().query(), qp().indexKey() ) );
+ matcher_.reset( new JSMatcher( qp().query() ) );
}
virtual void next() {
if ( !c_->ok() ) {
setComplete();
return;
}
- if ( matcher_->matches( c_->currKey(), c_->currLoc() ) ) {
+ if ( matcher_->matches( c_->currLoc().rec() ) ) {
one_ = c_->current();
setComplete();
} else {
@@ -80,7 +80,7 @@ namespace mongo {
private:
bool requireIndex_;
auto_ptr< Cursor > c_;
- auto_ptr< KeyValJSMatcher > matcher_;
+ auto_ptr< JSMatcher > matcher_;
BSONObj one_;
};
diff --git a/db/matcher.cpp b/db/matcher.cpp
index ad0563a6a60..78f3690fd33 100644
--- a/db/matcher.cpp
+++ b/db/matcher.cpp
@@ -115,25 +115,25 @@ namespace mongo {
namespace mongo {
- KeyValJSMatcher::KeyValJSMatcher(const BSONObj &_jsobj, const BSONObj &indexKeyPattern) :
- keyMatcher_(_jsobj.filterFieldsUndotted(indexKeyPattern, true), indexKeyPattern),
- recordMatcher_(_jsobj.filterFieldsUndotted(indexKeyPattern, false)) {
- }
-
- bool KeyValJSMatcher::matches(const BSONObj &key, const DiskLoc &recLoc, bool *deep) {
- if ( keyMatcher_.keyMatch() ) {
- if ( !keyMatcher_.matches(key, deep) ) {
- return false;
- }
- } else {
- if ( !keyMatcher_.matches(recLoc.rec(), deep) ) {
- return false;
- }
- }
- if ( recordMatcher_.trivial() )
- return true;
- return recordMatcher_.matches(recLoc.rec(), deep);
- }
+// KeyValJSMatcher::KeyValJSMatcher(const BSONObj &_jsobj, const BSONObj &indexKeyPattern) :
+// keyMatcher_(_jsobj.filterFieldsUndotted(indexKeyPattern, true), indexKeyPattern),
+// recordMatcher_(_jsobj.filterFieldsUndotted(indexKeyPattern, false)) {
+// }
+//
+// bool KeyValJSMatcher::matches(const BSONObj &key, const DiskLoc &recLoc, bool *deep) {
+// if ( keyMatcher_.keyMatch() ) {
+// if ( !keyMatcher_.matches(key, deep) ) {
+// return false;
+// }
+// } else {
+// if ( !keyMatcher_.matches(recLoc.rec(), deep) ) {
+// return false;
+// }
+// }
+// if ( recordMatcher_.trivial() )
+// return true;
+// return recordMatcher_.matches(recLoc.rec(), deep);
+// }
/* _jsobj - the query pattern
diff --git a/db/matcher.h b/db/matcher.h
index b89f70614f6..d9094da6057 100644
--- a/db/matcher.h
+++ b/db/matcher.h
@@ -143,15 +143,15 @@ namespace mongo {
int nBuilders;
};
- // If match succeeds on index key, then attempt to match full record.
- class KeyValJSMatcher : boost::noncopyable {
- public:
- KeyValJSMatcher(const BSONObj &pattern, const BSONObj &indexKeyPattern);
- bool matches(const BSONObj &j, bool *deep = 0);
- bool matches(const BSONObj &key, const DiskLoc &recLoc, bool *deep = 0);
- private:
- JSMatcher keyMatcher_;
- JSMatcher recordMatcher_;
- };
+// // If match succeeds on index key, then attempt to match full record.
+// class KeyValJSMatcher : boost::noncopyable {
+// public:
+// KeyValJSMatcher(const BSONObj &pattern, const BSONObj &indexKeyPattern);
+// bool matches(const BSONObj &j, bool *deep = 0);
+// bool matches(const BSONObj &key, const DiskLoc &recLoc, bool *deep = 0);
+// private:
+// JSMatcher keyMatcher_;
+// JSMatcher recordMatcher_;
+// };
} // namespace mongo
diff --git a/db/query.cpp b/db/query.cpp
index ff33e037dae..5164ba629b7 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -60,7 +60,7 @@ namespace mongo {
}
virtual void init() {
c_ = qp().newCursor();
- matcher_.reset( new KeyValJSMatcher( qp().query(), qp().indexKey() ) );
+ matcher_.reset( new JSMatcher( qp().query() ) );
}
virtual void next() {
if ( !c_->ok() ) {
@@ -71,7 +71,7 @@ namespace mongo {
DiskLoc rloc = c_->currLoc();
bool deep;
- if ( matcher_->matches(c_->currKey(), rloc, &deep) ) {
+ if ( matcher_->matches(rloc.rec(), &deep) ) {
if ( !deep || !c_->getsetdup(rloc) )
++count_;
}
@@ -99,7 +99,7 @@ namespace mongo {
int &bestCount_;
long long nScanned_;
auto_ptr< Cursor > c_;
- auto_ptr< KeyValJSMatcher > matcher_;
+ auto_ptr< JSMatcher > matcher_;
};
/* ns: namespace, e.g. <database>.<collection>
@@ -130,13 +130,13 @@ namespace mongo {
if( !c->ok() )
return nDeleted;
- KeyValJSMatcher matcher(pattern, c->indexKeyPattern());
+ JSMatcher matcher(pattern);
do {
DiskLoc rloc = c->currLoc();
bool deep;
- if ( !matcher.matches(c->currKey(), rloc, &deep) ) {
+ if ( !matcher.matches(rloc.rec(), &deep) ) {
c->advance(); // advance must be after noMoreMatches() because it uses currKey()
}
else {
@@ -545,7 +545,7 @@ namespace mongo {
if ( !c_->ok() )
setComplete();
else
- matcher_.reset( new KeyValJSMatcher( pattern, qp().indexKey() ) );
+ matcher_.reset( new JSMatcher( pattern ) );
}
virtual void next() {
if ( !c_->ok() ) {
@@ -553,7 +553,7 @@ namespace mongo {
return;
}
nscanned_++;
- if ( matcher_->matches(c_->currKey(), c_->currLoc()) ) {
+ if ( matcher_->matches(c_->currLoc().rec()) ) {
setComplete();
return;
}
@@ -568,7 +568,7 @@ namespace mongo {
private:
auto_ptr< Cursor > c_;
long long nscanned_;
- auto_ptr< KeyValJSMatcher > matcher_;
+ auto_ptr< JSMatcher > matcher_;
};
int __updateObjects(const char *ns, BSONObj updateobj, BSONObj &pattern, bool upsert, stringstream& ss, bool logop=false) {
@@ -810,7 +810,7 @@ namespace mongo {
break;
}
bool deep;
- if ( !cc->matcher->matches(c->currKey(), c->currLoc(), &deep) ) {
+ if ( !cc->matcher->matches(c->currLoc().rec(), &deep) ) {
}
else {
//out() << "matches " << c->currLoc().toString() << ' ' << deep << '\n';
@@ -860,7 +860,7 @@ namespace mongo {
if ( qp().exactKeyMatch() && fields_.empty() )
bc_ = dynamic_cast< BtreeCursor* >( c_.get() );
else
- matcher_.reset( new KeyValJSMatcher( query_, c_->indexKeyPattern() ) );
+ matcher_.reset( new JSMatcher( query_ ) );
}
virtual void next() {
if ( !c_->ok() ) {
@@ -885,7 +885,7 @@ namespace mongo {
}
} else {
bool deep;
- if ( !matcher_->matches(c_->currKey(), c_->currLoc(), &deep) ) {
+ if ( !matcher_->matches(c_->currLoc().rec(), &deep) ) {
}
else if ( !deep || !c_->getsetdup(c_->currLoc()) ) { // i.e., check for dups on deep items only
bool match = true;
@@ -916,7 +916,7 @@ namespace mongo {
BSONObj query_;
set< string > fields_;
BtreeCursor *bc_;
- auto_ptr< KeyValJSMatcher > matcher_;
+ auto_ptr< JSMatcher > matcher_;
BSONObj firstMatch_;
};
@@ -975,7 +975,7 @@ namespace mongo {
else
c_ = qp().newCursor();
- matcher_.reset(new KeyValJSMatcher(qp().query(), qp().indexKey()));
+ matcher_.reset(new JSMatcher(qp().query()));
if ( qp().scanAndOrderRequired() ) {
ordering_ = true;
@@ -988,7 +988,7 @@ namespace mongo {
if ( !c_->ok() ) {
findingStart_ = false;
c_ = qp().newCursor();
- } else if ( !matcher_->matches( c_->currKey(), c_->currLoc() ) ) {
+ } else if ( !matcher_->matches( c_->currLoc().rec() ) ) {
findingStart_ = false;
c_ = qp().newCursor( c_->currLoc() );
} else {
@@ -1004,7 +1004,7 @@ namespace mongo {
nscanned_++;
bool deep;
- if ( !matcher_->matches(c_->currKey(), c_->currLoc(), &deep) ) {
+ if ( !matcher_->matches(c_->currLoc().rec(), &deep) ) {
}
else if ( !deep || !c_->getsetdup(c_->currLoc()) ) { // i.e., check for dups on deep items only
BSONObj js = c_->current();
@@ -1079,7 +1079,7 @@ namespace mongo {
BufBuilder &builder() { return b_; }
bool scanAndOrderRequired() const { return ordering_; }
auto_ptr< Cursor > cursor() { return c_; }
- auto_ptr< KeyValJSMatcher > matcher() { return matcher_; }
+ auto_ptr< JSMatcher > matcher() { return matcher_; }
int n() const { return n_; }
long long nscanned() const { return nscanned_; }
bool saveClientCursor() const { return saveClientCursor_; }
@@ -1095,7 +1095,7 @@ namespace mongo {
auto_ptr< Cursor > c_;
long long nscanned_;
int queryOptions_;
- auto_ptr< KeyValJSMatcher > matcher_;
+ auto_ptr< JSMatcher > matcher_;
int n_;
int soSize_;
bool saveClientCursor_;
diff --git a/jstests/multi.js b/jstests/multi.js
new file mode 100644
index 00000000000..aec41145aa2
--- /dev/null
+++ b/jstests/multi.js
@@ -0,0 +1,6 @@
+t = db.jstests_multi;
+t.drop();
+
+t.ensureIndex( { a: 1 } );
+t.save( { a: [ 1, 2 ] } );
+assert.eq( 1, t.find( { a: { $gt: 0 } } ).count() );
diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj
index 3be68d6fe16..f393e231830 100644
--- a/mongo.xcodeproj/project.pbxproj
+++ b/mongo.xcodeproj/project.pbxproj
@@ -37,6 +37,7 @@
93278F670F72D39400844664 /* strategy_shard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = strategy_shard.cpp; sourceTree = "<group>"; };
932AC3EB0F4A5B34005BF8B0 /* queryoptimizertests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = queryoptimizertests.cpp; sourceTree = "<group>"; };
932AC4310F4A5E9D005BF8B0 /* SConstruct */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SConstruct; sourceTree = "<group>"; };
+ 9339D2610F8A5DD60063DBEF /* multi.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = multi.js; sourceTree = "<group>"; };
933A4D130F55A68600145C4B /* authTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = authTest.cpp; sourceTree = "<group>"; };
933A4D150F55A68600145C4B /* clientTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clientTest.cpp; sourceTree = "<group>"; };
933A4D170F55A68600145C4B /* first.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = first.cpp; sourceTree = "<group>"; };
@@ -539,6 +540,7 @@
93A8D1D10F37544800C92B85 /* jstests */ = {
isa = PBXGroup;
children = (
+ 9339D2610F8A5DD60063DBEF /* multi.js */,
93202DE40F879CB600AF3B71 /* all.js */,
93CCC87F0F8562E900E20FA0 /* datasize.js */,
93D949B40F7D2A7700C3C768 /* median.js */,