Permalink
Browse files

use firstElementFieldName()

  • Loading branch information...
dwight committed May 23, 2011
1 parent bd5b607 commit 8a0660ac31444b4e7c48442c0f44a01fbc9e4e07
View
@@ -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(); }
@@ -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 );
}
View
@@ -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;
View
@@ -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() ) {
View
@@ -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);
}
}
View
@@ -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 @@ namespace mongo {
}
if ( ( _scanAndOrderRequired || _order.isEmpty() ) &&
- !_frs.range( idxKey.firstElement().fieldName() ).nontrivial() ) {
+ !_frs.range( idxKey.firstElementFieldName() ).nontrivial() ) {
_unhelpful = true;
}
}
@@ -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();
@@ -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 ) );
}
@@ -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;
@@ -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;
}
View
@@ -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() ) ) {
View
@@ -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<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 ) {
@@ -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;
View
@@ -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() );
}
};
@@ -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 );
{
View
@@ -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();
View
@@ -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);
View
@@ -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;
}
View
@@ -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());
View
@@ -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);
}
@@ -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() ) ) ) );

0 comments on commit 8a0660a

Please sign in to comment.