Permalink
Browse files

SERVER-3192 require atomic specifier to be top level

  • Loading branch information...
1 parent d7908f6 commit fc3f8343201cabcc1a5c99b7f6a12f5c25647b9b @astaple astaple committed Jun 15, 2011
Showing with 12 additions and 6 deletions.
  1. +5 −4 db/matcher.cpp
  2. +2 −2 db/matcher.h
  3. +5 −0 jstests/remove2.js
View
@@ -286,7 +286,7 @@ namespace mongo {
while( j.more() ) {
BSONElement f = j.next();
uassert( 13087, "$and/$or/$nor match element must be an object", f.type() == Object );
- matchers.push_back( shared_ptr< Matcher >( new Matcher( f.embeddedObject() ) ) );
+ matchers.push_back( shared_ptr< Matcher >( new Matcher( f.embeddedObject(), true ) ) );
}
}
@@ -309,7 +309,7 @@ namespace mongo {
return true;
}
- void Matcher::parseMatchExpressionElement( const BSONElement &e ) {
+ void Matcher::parseMatchExpressionElement( const BSONElement &e, bool nested ) {
uassert( 13629 , "can't have undefined in a query expression" , e.type() != Undefined );
@@ -405,6 +405,7 @@ namespace mongo {
_hasArray = true;
}
else if( strcmp(e.fieldName(), "$atomic") == 0 ) {
+ uassert( 14844, "$atomic specifier must be a top level field", !nested );
_atomic = e.trueValue();
return;
}
@@ -415,12 +416,12 @@ namespace mongo {
/* _jsobj - the query pattern
*/
- Matcher::Matcher(const BSONObj &jsobj) :
+ Matcher::Matcher(const BSONObj &jsobj, bool nested) :
_where(0), _jsobj(jsobj), _haveSize(), _all(), _hasArray(0), _haveNeg(), _atomic(false), _nRegex(0) {
BSONObjIterator i(_jsobj);
while ( i.more() ) {
- parseMatchExpressionElement( i.next() );
+ parseMatchExpressionElement( i.next(), nested );
}
}
View
@@ -134,7 +134,7 @@ namespace mongo {
return op <= BSONObj::LTE ? -1 : 1;
}
- Matcher(const BSONObj &pattern);
+ Matcher(const BSONObj &pattern, bool nested=false);
~Matcher();
@@ -182,7 +182,7 @@ namespace mongo {
bool parseClause( const BSONElement &e );
void parseExtractedClause( const BSONElement &e, list< shared_ptr< Matcher > > &matchers );
- void parseMatchExpressionElement( const BSONElement &e );
+ void parseMatchExpressionElement( const BSONElement &e, bool nested );
Where *_where; // set if query uses $where
BSONObj _jsobj; // the query pattern. e.g., { name: "joe" }
View
@@ -21,6 +21,11 @@ function g() {
t.save( { x:[7,8,9], z:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" } );
t.remove( {x : {$gte:3}, $atomic:x++ } );
+
+ assert( !db.getLastError() );
+ // $atomic within $and is not allowed.
+ t.remove( {x : {$gte:3}, $and:[{$atomic:true}] } );
+ assert( db.getLastError() );
assert( t.findOne({x:3}) == null );
assert( t.findOne({x:8}) == null );

0 comments on commit fc3f834

Please sign in to comment.