Skip to content

Commit

Permalink
use firstElementFieldName()
Browse files Browse the repository at this point in the history
  • Loading branch information
dwight committed May 24, 2011
1 parent bd5b607 commit 8a0660a
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bson/bsonelement.h
Expand Up @@ -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(); }
Expand Down
4 changes: 2 additions & 2 deletions client/syncclusterconnection.cpp
Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion db/dbcommands_admin.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion db/dbhelpers.cpp
Expand Up @@ -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() ) {
Expand Down
2 changes: 1 addition & 1 deletion db/projection.cpp
Expand Up @@ -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);
}

}
Expand Down
12 changes: 6 additions & 6 deletions db/queryoptimizer.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ namespace mongo {
}

if ( ( _scanAndOrderRequired || _order.isEmpty() ) &&
!_frs.range( idxKey.firstElement().fieldName() ).nontrivial() ) {
!_frs.range( idxKey.firstElementFieldName() ).nontrivial() ) {
_unhelpful = true;
}
}
Expand Down Expand Up @@ -347,7 +347,7 @@ namespace mongo {
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();
Expand Down Expand Up @@ -442,7 +442,7 @@ namespace mongo {
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 ) );
}
Expand Down Expand Up @@ -477,7 +477,7 @@ namespace mongo {

// 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;
Expand Down Expand Up @@ -1163,7 +1163,7 @@ namespace mongo {
return true;

if ( e.type() == Object )
return e.Obj().firstElement().fieldName()[0] != '$';
return e.Obj().firstElementFieldName()[0] != '$';

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion db/queryutil.cpp
Expand Up @@ -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() ) ) {
Expand Down
6 changes: 3 additions & 3 deletions db/update.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -1040,7 +1040,7 @@ namespace mongo {
/* end note */

auto_ptr<ModSet> 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 ) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dbtests/jsobjtests.cpp
Expand Up @@ -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() );
}
};

Expand Down
6 changes: 3 additions & 3 deletions dbtests/queryoptimizertests.cpp
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 );
{
Expand Down
2 changes: 1 addition & 1 deletion dbtests/querytests.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion s/chunk.cpp
Expand Up @@ -691,7 +691,7 @@ namespace mongo {
boost::scoped_ptr<FieldRangeSetPair> 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);
Expand Down
2 changes: 1 addition & 1 deletion s/d_split.cpp
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions s/strategy_shard.cpp
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion s/strategy_single.cpp
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion scripting/engine_spidermonkey.cpp
Expand Up @@ -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() ) ) ) );
Expand Down

0 comments on commit 8a0660a

Please sign in to comment.