diff --git a/bson/bsonelement.h b/bson/bsonelement.h index a6bf23e825b..504b542154a 100644 --- a/bson/bsonelement.h +++ b/bson/bsonelement.h @@ -153,7 +153,7 @@ namespace mongo { You must assure element is a boolean before calling. */ bool boolean() const { - return *value(); // ? true : false; + return *value() ? true : false; } bool booleanSafe() const { return isBoolean() && boolean(); } diff --git a/client/syncclusterconnection.cpp b/client/syncclusterconnection.cpp index b792250291c..3c9bd926a61 100644 --- a/client/syncclusterconnection.cpp +++ b/client/syncclusterconnection.cpp @@ -159,7 +159,7 @@ namespace mongo { BSONObj SyncClusterConnection::findOne(const string &ns, const Query& query, const BSONObj *fieldsToReturn, int queryOptions) { if ( ns.find( ".$cmd" ) != string::npos ) { - string cmdName = query.obj.firstElement().fieldName(); + string cmdName = query.obj.firstElementFieldName(); int lockType = _lockType( cmdName ); @@ -199,7 +199,7 @@ namespace mongo { const BSONObj *fieldsToReturn, int queryOptions, int batchSize ) { _lastErrors.clear(); if ( ns.find( ".$cmd" ) != string::npos ) { - string cmdName = query.obj.firstElement().fieldName(); + string cmdName = query.obj.firstElementFieldName(); int lockType = _lockType( cmdName ); uassert( 13054 , (string)"write $cmd not supported in SyncClusterConnection::query for:" + cmdName , lockType <= 0 ); } diff --git a/db/dbcommands_admin.cpp b/db/dbcommands_admin.cpp index 9e9ae115e37..5ee88cd1441 100644 --- a/db/dbcommands_admin.cpp +++ b/db/dbcommands_admin.cpp @@ -258,7 +258,7 @@ namespace mongo { errors << "invalid bson object detected (see logs for more info)"; nInvalid++; - if (strcmp("_id", obj.firstElement().fieldName()) == 0){ + if (strcmp("_id", obj.firstElementFieldName()) == 0){ try { obj.firstElement().validate(); // throws on error log() << "Invalid bson detected in " << ns << " with _id: " << obj.firstElement().toString(false) << endl; diff --git a/db/dbhelpers.cpp b/db/dbhelpers.cpp index 334a42fba01..ffdcb62e248 100644 --- a/db/dbhelpers.cpp +++ b/db/dbhelpers.cpp @@ -63,7 +63,7 @@ namespace mongo { public: FindOne( bool requireIndex ) : requireIndex_( requireIndex ) {} virtual void _init() { - if ( requireIndex_ && strcmp( qp().indexKey().firstElement().fieldName(), "$natural" ) == 0 ) + if ( requireIndex_ && strcmp( qp().indexKey().firstElementFieldName(), "$natural" ) == 0 ) throw MsgAssertionException( 9011 , "Not an index cursor" ); c_ = qp().newCursor(); if ( !c_->ok() ) { diff --git a/db/projection.cpp b/db/projection.cpp index 3dcfef73d08..d07e56527af 100644 --- a/db/projection.cpp +++ b/db/projection.cpp @@ -61,7 +61,7 @@ namespace mongo { } } else { - uassert(13097, string("Unsupported projection option: ") + obj.firstElement().fieldName(), false); + uassert(13097, string("Unsupported projection option: ") + obj.firstElementFieldName(), false); } } diff --git a/db/queryoptimizer.cpp b/db/queryoptimizer.cpp index 2397d67b569..bda44c4cd9c 100644 --- a/db/queryoptimizer.cpp +++ b/db/queryoptimizer.cpp @@ -78,7 +78,7 @@ namespace mongo { } if ( willScanTable() ) { - if ( _order.isEmpty() || !strcmp( _order.firstElement().fieldName(), "$natural" ) ) + if ( _order.isEmpty() || !strcmp( _order.firstElementFieldName(), "$natural" ) ) _scanAndOrderRequired = false; return; } @@ -184,7 +184,7 @@ doneCheckOrder: } if ( ( _scanAndOrderRequired || _order.isEmpty() ) && - !_frs.range( idxKey.firstElement().fieldName() ).nontrivial() ) { + !_frs.range( idxKey.firstElementFieldName() ).nontrivial() ) { _unhelpful = true; } } @@ -347,7 +347,7 @@ doneCheckOrder: else if( hint.type() == Object ) { BSONObj hintobj = hint.embeddedObject(); uassert( 10112 , "bad hint", !hintobj.isEmpty() ); - if ( !strcmp( hintobj.firstElement().fieldName(), "$natural" ) ) { + if ( !strcmp( hintobj.firstElementFieldName(), "$natural" ) ) { return 0; } NamespaceDetails::IndexIterator i = d->ii(); @@ -442,7 +442,7 @@ doneCheckOrder: if ( !bestIndex.isEmpty() ) { QueryPlanPtr p; _oldNScanned = oldNScanned; - if ( !strcmp( bestIndex.firstElement().fieldName(), "$natural" ) ) { + if ( !strcmp( bestIndex.firstElementFieldName(), "$natural" ) ) { // Table scan plan p.reset( new QueryPlan( d, -1, *_frsp, *_originalFrsp, _originalQuery, _order ) ); } @@ -477,7 +477,7 @@ doneCheckOrder: // If table scan is optimal or natural order requested or tailable cursor requested if ( !_frsp->matchPossible() || ( _frsp->noNontrivialRanges() && _order.isEmpty() ) || - ( !_order.isEmpty() && !strcmp( _order.firstElement().fieldName(), "$natural" ) ) ) { + ( !_order.isEmpty() && !strcmp( _order.firstElementFieldName(), "$natural" ) ) ) { // Table scan plan addPlan( QueryPlanPtr( new QueryPlan( d, -1, *_frsp, *_originalFrsp, _originalQuery, _order ) ), checkFirst ); return; @@ -1163,7 +1163,7 @@ doneCheckOrder: return true; if ( e.type() == Object ) - return e.Obj().firstElement().fieldName()[0] != '$'; + return e.Obj().firstElementFieldName()[0] != '$'; return false; } diff --git a/db/queryutil.cpp b/db/queryutil.cpp index ed64a67fadd..55e19d05557 100644 --- a/db/queryutil.cpp +++ b/db/queryutil.cpp @@ -773,7 +773,7 @@ namespace mongo { void FieldRangeSet::processQueryField( const BSONElement &e, bool optimize ) { bool equality = ( getGtLtOp( e ) == BSONObj::Equality ); if ( equality && e.type() == Object ) { - equality = ( strcmp( e.embeddedObject().firstElement().fieldName(), "$not" ) != 0 ); + equality = ( strcmp( e.embeddedObject().firstElementFieldName(), "$not" ) != 0 ); } if ( equality || ( e.type() == Object && !e.embeddedObject()[ "$regex" ].eoo() ) ) { diff --git a/db/update.cpp b/db/update.cpp index ac66b354ab1..c1bfae2f950 100644 --- a/db/update.cpp +++ b/db/update.cpp @@ -756,7 +756,7 @@ namespace mongo { if ( e.fieldName()[0] == '$' ) // for $atomic and anything else we add continue; - if ( e.type() == Object && e.embeddedObject().firstElement().fieldName()[0] == '$' ) { + if ( e.type() == Object && e.embeddedObject().firstElementFieldName()[0] == '$' ) { // this means this is a $gt type filter, so don't make part of the new object continue; } @@ -1040,7 +1040,7 @@ namespace mongo { /* end note */ auto_ptr mods; - bool isOperatorUpdate = updateobj.firstElement().fieldName()[0] == '$'; + bool isOperatorUpdate = updateobj.firstElementFieldName()[0] == '$'; int modsIsIndexed = false; // really the # of indexes if ( isOperatorUpdate ) { if( d && d->indexBuildInProgress ) { @@ -1251,7 +1251,7 @@ namespace mongo { debug.nscanned = (int) nscanned; if ( upsert ) { - if ( updateobj.firstElement().fieldName()[0] == '$' ) { + if ( updateobj.firstElementFieldName()[0] == '$' ) { /* upsert of an $inc. build a default */ BSONObj newObj = mods->createNewFromQuery( patternOrig ); debug.fastmodinsert = true; diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp index 6abe1b3cdb0..ea743559dc0 100644 --- a/dbtests/jsobjtests.cpp +++ b/dbtests/jsobjtests.cpp @@ -1248,7 +1248,7 @@ namespace JsobjTests { assert( BSON( "b" << 11 ).woCompare( x.extractFields( BSON( "b" << 1 ) ) ) == 0 ); assert( x.woCompare( x.extractFields( BSON( "a" << 1 << "b" << 1 ) ) ) == 0 ); - assert( (string)"a" == x.extractFields( BSON( "a" << 1 << "c" << 1 ) ).firstElement().fieldName() ); + assert( (string)"a" == x.extractFields( BSON( "a" << 1 << "c" << 1 ) ).firstElementFieldName() ); } }; diff --git a/dbtests/queryoptimizertests.cpp b/dbtests/queryoptimizertests.cpp index 5ab455d570b..97198e4877a 100644 --- a/dbtests/queryoptimizertests.cpp +++ b/dbtests/queryoptimizertests.cpp @@ -712,7 +712,7 @@ namespace QueryOptimizerTests { TestOp() {} virtual void _init() {} virtual void next() { - if ( qp().indexKey().firstElement().fieldName() == string( "$natural" ) ) + if ( qp().indexKey().firstElementFieldName() == string( "$natural" ) ) massert( 10410 , "throw", false ); setComplete(); } @@ -942,11 +942,11 @@ namespace QueryOptimizerTests { boost::shared_ptr< Cursor > c = bestGuessCursor( ns(), BSON( "b" << 1 ), BSON( "a" << 1 ) ); ASSERT_EQUALS( string( "a" ), c->indexKeyPattern().firstElement().fieldName() ); c = bestGuessCursor( ns(), BSON( "a" << 1 ), BSON( "b" << 1 ) ); - ASSERT_EQUALS( string( "b" ), c->indexKeyPattern().firstElement().fieldName() ); + ASSERT_EQUALS( string( "b" ), c->indexKeyPattern().firstElementFieldName() ); boost::shared_ptr< MultiCursor > m = dynamic_pointer_cast< MultiCursor >( bestGuessCursor( ns(), fromjson( "{b:1,$or:[{z:1}]}" ), BSON( "a" << 1 ) ) ); ASSERT_EQUALS( string( "a" ), m->sub_c()->indexKeyPattern().firstElement().fieldName() ); m = dynamic_pointer_cast< MultiCursor >( bestGuessCursor( ns(), fromjson( "{a:1,$or:[{y:1}]}" ), BSON( "b" << 1 ) ) ); - ASSERT_EQUALS( string( "b" ), m->sub_c()->indexKeyPattern().firstElement().fieldName() ); + ASSERT_EQUALS( string( "b" ), m->sub_c()->indexKeyPattern().firstElementFieldName() ); FieldRangeSet frs( "ns", BSON( "a" << 1 ), true ); { diff --git a/dbtests/querytests.cpp b/dbtests/querytests.cpp index 073d9242874..5440f886bbf 100644 --- a/dbtests/querytests.cpp +++ b/dbtests/querytests.cpp @@ -60,7 +60,7 @@ namespace QueryTests { } static void addIndex( const BSONObj &key ) { BSONObjBuilder b; - b.append( "name", key.firstElement().fieldName() ); + b.append( "name", key.firstElementFieldName() ); b.append( "ns", ns() ); b.append( "key", key ); BSONObj o = b.done(); diff --git a/s/chunk.cpp b/s/chunk.cpp index c8e80120dc2..945b52d2570 100644 --- a/s/chunk.cpp +++ b/s/chunk.cpp @@ -691,7 +691,7 @@ namespace mongo { boost::scoped_ptr frsp (org.topFrsp()); { // special case if most-significant field isn't in query - FieldRange range = frsp->singleKeyRange(_key.key().firstElement().fieldName()); + FieldRange range = frsp->singleKeyRange(_key.key().firstElementFieldName()); if ( !range.nontrivial() ) { DEV PRINT(range.nontrivial()); getAllShards(shards); diff --git a/s/d_split.cpp b/s/d_split.cpp index 5163c474d2b..1cf5dcb0c7c 100644 --- a/s/d_split.cpp +++ b/s/d_split.cpp @@ -141,7 +141,7 @@ namespace mongo { const char* ns = jsobj.getStringField( "checkShardingIndex" ); BSONObj keyPattern = jsobj.getObjectField( "keyPattern" ); - if ( keyPattern.nFields() == 1 && str::equals( "_id" , keyPattern.firstElement().fieldName() ) ) { + if ( keyPattern.nFields() == 1 && str::equals( "_id" , keyPattern.firstElementFieldName() ) ) { result.appendBool( "idskip" , true ); return true; } diff --git a/s/strategy_shard.cpp b/s/strategy_shard.cpp index 0b723aeb6c4..9d625f11d0a 100644 --- a/s/strategy_shard.cpp +++ b/s/strategy_shard.cpp @@ -213,7 +213,7 @@ namespace mongo { if (upsert) { uassert(8012, "can't upsert something without shard key", (manager->hasShardKey(toupdate) || - (toupdate.firstElement().fieldName()[0] == '$' && manager->hasShardKey(query)))); + (toupdate.firstElementFieldName()[0] == '$' && manager->hasShardKey(query)))); BSONObj key = manager->getShardKey().extractKey(query); BSONForEach(e, key) { @@ -225,7 +225,7 @@ namespace mongo { if ( ! manager->hasShardKey( query ) ) { if ( multi ) { } - else if ( strcmp( query.firstElement().fieldName() , "_id" ) || query.nFields() != 1 ) { + else if ( strcmp( query.firstElementFieldName() , "_id" ) || query.nFields() != 1 ) { throw UserException( 8013 , "can't do non-multi update with query that doesn't have the shard key" ); } else { @@ -236,7 +236,7 @@ namespace mongo { if ( ! save ) { - if ( toupdate.firstElement().fieldName()[0] == '$' ) { + if ( toupdate.firstElementFieldName()[0] == '$' ) { BSONObjIterator ops(toupdate); while(ops.more()) { BSONElement op(ops.next()); diff --git a/s/strategy_single.cpp b/s/strategy_single.cpp index 5f233f83cf9..b364880e5c6 100644 --- a/s/strategy_single.cpp +++ b/s/strategy_single.cpp @@ -81,7 +81,7 @@ namespace mongo { } } - string commandName = q.query.firstElement().fieldName(); + string commandName = q.query.firstElementFieldName(); uassert(13390, "unrecognized command: " + commandName, _commandsSafeToPass.count(commandName) != 0); } diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index 5f7551ce93a..9e55397a4cd 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -531,7 +531,7 @@ namespace mongo { JSObject * toJSObject( const BSONObj * obj , bool readOnly=false ) { static string ref = "$ref"; - if ( ref == obj->firstElement().fieldName() ) { + if ( ref == obj->firstElementFieldName() ) { JSObject * o = JS_NewObject( _context , &dbref_class , NULL, NULL); CHECKNEWOBJECT(o,_context,"toJSObject1"); assert( JS_SetPrivate( _context , o , (void*)(new BSONHolder( obj->getOwned() ) ) ) );