virtual bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { if( cmdObj.hasElement("expireOplogDays") || cmdObj.hasElement("expireOplogHours") ) { uint32_t expireOplogDays = cmdLine.expireOplogDays; uint32_t expireOplogHours = cmdLine.expireOplogHours; if (cmdObj.hasElement("expireOplogHours")) { BSONElement e = cmdObj["expireOplogHours"]; if (!e.isNumber()) { errmsg = "bad expireOplogHours"; return false; } expireOplogHours = e.numberLong(); } if (cmdObj.hasElement("expireOplogDays")) { BSONElement e = cmdObj["expireOplogDays"]; if (!e.isNumber()) { errmsg = "bad expireOplogDays"; return false; } expireOplogDays = e.numberLong(); } theReplSet->changeExpireOplog(expireOplogDays, expireOplogHours); } return true; }
bool GeoParser::isLegacyCenterSphere(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } bool isCenterSphere = mongoutils::str::equals(type.fieldName(), "$centerSphere"); if (!isCenterSphere) { return false; } BSONObjIterator objIt(type.embeddedObject()); BSONElement center = objIt.next(); if (!center.isABSONObj()) { return false; } if (!isLegacyPoint(center.Obj())) { return false; } if (!objIt.more()) { return false; } BSONElement radius = objIt.next(); if (!radius.isNumber()) { return false; } return true; }
/* wo = "well ordered" */ int BSONElement::woCompare( const BSONElement &e, bool considerFieldName ) const { int lt = (int) canonicalType(); int rt = (int) e.canonicalType(); int x = lt - rt; if( x != 0 && (!isNumber() || !e.isNumber()) ) return x; if ( considerFieldName ) { x = strcmp(fieldName(), e.fieldName()); if ( x != 0 ) return x; } x = compareElementValues(*this, e); return x; }
bool GeoParser::parsePointWithMaxDistance(const BSONObj& obj, PointWithCRS* out, double* maxOut) { BSONObjIterator it(obj); if (!it.more()) { return false; } BSONElement lng = it.next(); if (!lng.isNumber()) { return false; } if (!it.more()) { return false; } BSONElement lat = it.next(); if (!lat.isNumber()) { return false; } if (!it.more()) { return false; } BSONElement dist = it.next(); if (!dist.isNumber()) { return false; } if (it.more()) { return false; } out->oldPoint.x = lng.number(); out->oldPoint.y = lat.number(); out->crs = FLAT; *maxOut = dist.number(); return true; }
MongoProgramRunner( const BSONObj &args ) { assert( args.nFields() > 0 ); string program( args.firstElement().valuestrsafe() ); assert( !program.empty() ); boost::filesystem::path programPath = ( boost::filesystem::path( argv0 ) ).branch_path() / program; massert( "couldn't find " + programPath.native_file_string(), boost::filesystem::exists( programPath ) ); port_ = -1; argv_ = new char *[ args.nFields() + 1 ]; { string s = programPath.native_file_string(); if ( s == program ) s = "./" + s; argv_[ 0 ] = copyString( s.c_str() ); } BSONObjIterator j( args ); j.next(); for( int i = 1; i < args.nFields(); ++i ) { BSONElement e = j.next(); string str; if ( e.isNumber() ) { stringstream ss; ss << e.number(); str = ss.str(); } else { assert( e.type() == mongo::String ); str = e.valuestr(); } char *s = copyString( str.c_str() ); if ( string( "--port" ) == s ) port_ = -2; else if ( port_ == -2 ) port_ = strtol( s, 0, 10 ); argv_[ i ] = s; } argv_[ args.nFields() ] = 0; if ( program != "mongod" && program != "mongos" && program != "mongobridge" ) port_ = 0; else assert( port_ > 0 ); if ( port_ > 0 && dbs.count( port_ ) != 0 ){ cerr << "count for port: " << port_ << " is not 0 is: " << dbs.count( port_ ) << endl; assert( dbs.count( port_ ) == 0 ); } }
auto_ptr<DBClientCursor> DBClientReplicaSet::checkSlaveQueryResult( auto_ptr<DBClientCursor> result ){ BSONObj error; bool isError = result->peekError( &error ); if( ! isError ) return result; // We only check for "not master or secondary" errors here // If the error code here ever changes, we need to change this code also BSONElement code = error["code"]; if( code.isNumber() && code.Int() == 13436 /* not master or secondary */ ){ isntSecondary(); throw DBException( str::stream() << "slave " << _slaveHost.toString() << " is no longer secondary", 14812 ); } return result; }
unsigned long long extractVersion( BSONElement e , string& errmsg ) { if ( e.eoo() ) { errmsg = "no version"; return 0; } if ( e.isNumber() ) return (unsigned long long)e.number(); if ( e.type() == Date || e.type() == Timestamp ) return e._numberLong(); errmsg = "version is not a numeric type"; return 0; }
bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { const string ns = dbname + "." + cmdObj.firstElement().valuestr(); Client::ReadContext ctx(ns); Database* db = ctx.ctx().db(); if ( !db ) { errmsg = "can't find ns"; return false; } Collection* collection = db->getCollection( ns ); if ( !collection ) { errmsg = "can't find ns"; return false; } vector<IndexDescriptor*> idxs; collection->getIndexCatalog()->findIndexByType(IndexNames::GEO_HAYSTACK, idxs); if (idxs.size() == 0) { errmsg = "no geoSearch index"; return false; } if (idxs.size() > 1) { errmsg = "more than 1 geosearch index"; return false; } BSONElement nearElt = cmdObj["near"]; BSONElement maxDistance = cmdObj["maxDistance"]; BSONElement search = cmdObj["search"]; uassert(13318, "near needs to be an array", nearElt.isABSONObj()); uassert(13319, "maxDistance needs a number", maxDistance.isNumber()); uassert(13320, "search needs to be an object", search.type() == Object); unsigned limit = 50; if (cmdObj["limit"].isNumber()) limit = static_cast<unsigned>(cmdObj["limit"].numberInt()); IndexDescriptor* desc = idxs[0]; HaystackAccessMethod* ham = static_cast<HaystackAccessMethod*>( collection->getIndexCatalog()->getIndex(desc) ); ham->searchCommand(collection, nearElt.Obj(), maxDistance.numberDouble(), search.Obj(), &result, limit); return 1; }
Status ModifierInc::init(const BSONElement& modExpr, const Options& opts, bool* positional) { // // field name analysis // // Perform standard field name and updateable checks. _fieldRef.parse(modExpr.fieldName()); Status status = fieldchecker::isUpdatable(_fieldRef); if (! status.isOK()) { return status; } // If a $-positional operator was used, get the index in which it occurred // and ensure only one occurrence. size_t foundCount; bool foundDollar = fieldchecker::isPositional(_fieldRef, &_posDollar, &foundCount); if (positional) *positional = foundDollar; if (foundDollar && foundCount > 1) { return Status(ErrorCodes::BadValue, str::stream() << "Too many positional (i.e. '$') elements found in path '" << _fieldRef.dottedField() << "'"); } // // value analysis // if (!modExpr.isNumber()) { // TODO: Context for mod error messages would be helpful // include mod code, etc. return Status(ErrorCodes::TypeMismatch, str::stream() << "Cannot " << (_mode == MODE_INC ? "increment" : "multiply") << " with non-numeric argument: {" << modExpr << "}"); } _val = modExpr; dassert(_val.isValid()); return Status::OK(); }
intrusive_ptr<DocumentSource> DocumentSourceSkip::createFromBson( BSONElement elem, const intrusive_ptr<ExpressionContext> &pExpCtx) { uassert(15972, str::stream() << DocumentSourceSkip::skipName << ": the value to skip must be a number", elem.isNumber()); intrusive_ptr<DocumentSourceSkip> pSkip( DocumentSourceSkip::create(pExpCtx)); pSkip->_skip = elem.numberLong(); uassert(15956, str::stream() << DocumentSourceSkip::skipName << ": the number to skip cannot be negative", pSkip->_skip >= 0); return pSkip; }
string DBClientWithCommands::genIndexName( const BSONObj& keys ) { stringstream ss; bool first = 1; for ( BSONObjIterator i(keys); i.more(); ) { BSONElement f = i.next(); if ( first ) first = 0; else ss << "_"; ss << f.fieldName() << "_"; if( f.isNumber() ) ss << f.numberInt(); } return ss.str(); }
static double twoDSphereBoundsIncrement(const IndexDescriptor* s2Index) { // The user can override this so we honor it. We could ignore it though -- it's just used // to set _radiusIncrement, not to do any covering. // TODO: Make this parsed somewhere else int finestIndexedLevel; BSONElement finestLevelEl = s2Index->infoObj()["finestIndexedLevel"]; if (finestLevelEl.isNumber()) { finestIndexedLevel = finestLevelEl.numberInt(); } else { finestIndexedLevel = S2::kAvgEdge.GetClosestLevel(500.0 / kRadiusOfEarthInMeters); } // Start with a conservative bounds increment. When we're done searching a shell we // increment the two radii by this. return 5 * S2::kAvgEdge.GetValue(finestIndexedLevel) * kRadiusOfEarthInMeters; }
bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { string ns = dbname + "." + cmdObj.firstElement().valuestr(); NamespaceDetails * d = nsdetails( ns.c_str() ); if ( ! d ) { errmsg = "can't find ns"; return false; } vector<int> idxs; d->findIndexByType( GEOSEARCHNAME , idxs ); if ( idxs.size() == 0 ) { errmsg = "no geoSearch index"; return false; } if ( idxs.size() > 1 ) { errmsg = "more than 1 geosearch index"; return false; } int idxNum = idxs[0]; IndexDetails& id = d->idx( idxNum ); GeoHaystackSearchIndex * si = (GeoHaystackSearchIndex*)id.getSpec().getType(); verify( &id == si->getDetails() ); BSONElement n = cmdObj["near"]; BSONElement maxDistance = cmdObj["maxDistance"]; BSONElement search = cmdObj["search"]; uassert( 13318 , "near needs to be an array" , n.isABSONObj() ); uassert( 13319 , "maxDistance needs a number" , maxDistance.isNumber() ); uassert( 13320 , "search needs to be an object" , search.type() == Object ); unsigned limit = 50; if ( cmdObj["limit"].isNumber() ) limit = (unsigned)cmdObj["limit"].numberInt(); si->searchCommand( d , idxNum , n.Obj() , maxDistance.numberDouble() , search.Obj() , result , limit ); return 1; }
// static void QueryPlannerIXSelect::stripInvalidAssignmentsTo2dsphereIndices( MatchExpression* node, const vector<IndexEntry>& indices) { for (size_t i = 0; i < indices.size(); ++i) { const IndexEntry& index = indices[i]; // We only worry about 2dsphere indices. if (INDEX_2DSPHERE != index.type) { continue; } // They also have to be V2. Both ignore the sparse flag but V1 is // never-sparse, V2 geo-sparse. BSONElement elt = index.infoObj["2dsphereIndexVersion"]; if (elt.eoo()) { continue; } if (!elt.isNumber()) { continue; } if (2 != elt.numberInt()) { continue; } // If every field is geo don't bother doing anything. bool allFieldsGeo = true; BSONObjIterator it(index.keyPattern); while (it.more()) { BSONElement elt = it.next(); if (String != elt.type()) { allFieldsGeo = false; break; } } if (allFieldsGeo) { continue; } // Remove bad assignments from this index. stripInvalidAssignmentsTo2dsphereIndex(node, i); } }
/* This is for languages whose "objects" are not well ordered (JSON is well ordered). [ { a : ... } , { b : ... } ] -> { a : ..., b : ... } */ static BSONObj transformOrderFromArrayFormat(BSONObj order) { /* note: this is slow, but that is ok as order will have very few pieces */ BSONObjBuilder b; char p[2] = "0"; while ( 1 ) { BSONObj j = order.getObjectField(p); if ( j.isEmpty() ) break; BSONElement e = j.firstElement(); uassert( 10102 , "bad order array", !e.eoo()); uassert( 10103 , "bad order array [2]", e.isNumber()); b.append(e); (*p)++; uassert( 10104 , "too many ordering elements", *p <= '9'); } return b.obj(); }
// static bool LiteParsedQuery::isValidSortOrder(const BSONObj& sortObj) { BSONObjIterator i(sortObj); while (i.more()) { BSONElement e = i.next(); // fieldNameSize() includes NULL terminator. For empty field name, // we should be checking for 1 instead of 0. if (1 == e.fieldNameSize()) { return false; } if (isTextScoreMeta(e)) { continue; } long long n = e.safeNumberLong(); if (!(e.isNumber() && (n == -1LL || n == 1LL))) { return false; } } return true; }
bool DBClientBase::ensureIndex( const string &ns , BSONObj keys , bool unique, const string & name ) { BSONObjBuilder toSave; toSave.append( "ns" , ns ); toSave.append( "key" , keys ); string cacheKey(ns); cacheKey += "--"; if ( name != "" ) { toSave.append( "name" , name ); cacheKey += name; } else { stringstream ss; bool first = 1; for ( BSONObjIterator i(keys); i.more(); ) { BSONElement f = i.next(); if ( first ) first = 0; else ss << "_"; ss << f.fieldName() << "_"; if( f.isNumber() ) ss << f.numberInt(); } toSave.append( "name" , ss.str() ); cacheKey += ss.str(); } if ( unique ) toSave.appendBool( "unique", unique ); if ( _seenIndexes.count( cacheKey ) ) return 0; _seenIndexes.insert( cacheKey ); insert( Namespace( ns.c_str() ).getSisterNS( "system.indexes" ).c_str() , toSave.obj() ); return 1; }
/** * Returns the projected value from the working set that would * be returned in the 'values' field of the distinct command result. * Limited to NumberInt BSON types because this is the only * BSON type used in this suite of tests. */ static int getIntFieldDotted(const WorkingSet& ws, WorkingSetID wsid, const std::string& field) { // For some reason (at least under OS X clang), we cannot refer to INVALID_ID // inside the test assertion macro. WorkingSetID invalid = WorkingSet::INVALID_ID; ASSERT_NOT_EQUALS(invalid, wsid); WorkingSetMember* member = ws.get(wsid); // Distinct hack execution is always covered. // Key value is retrieved from working set key data // instead of RecordId. ASSERT_FALSE(member->hasObj()); BSONElement keyElt; ASSERT_TRUE(member->getFieldDotted(field, &keyElt)); ASSERT_TRUE(keyElt.isNumber()); return keyElt.numberInt(); }
INT32 catSplitCleanup( const BSONObj & splitInfo, pmdEDUCB * cb, INT16 w ) { INT32 rc = SDB_OK ; UINT64 taskID = 0 ; INT32 status = CLS_TASK_STATUS_READY ; BSONElement ele = splitInfo.getField( CAT_TASKID_NAME ) ; PD_CHECK( ele.isNumber(), SDB_INVALIDARG, error, PDERROR, "Failed to get field[%s], type: %d", CAT_TASKID_NAME, ele.type() ) ; taskID = ( UINT64 )ele.numberLong() ; rc = catGetTaskStatus( taskID, status, cb ) ; if ( rc ) { goto error ; } if ( CLS_TASK_STATUS_META == status ) { rc = catUpdateTaskStatus( taskID, CLS_TASK_STATUS_FINISH, cb, w ) ; if ( rc ) { goto error ; } } else if ( CLS_TASK_STATUS_FINISH == status ) { } else { PD_LOG( PDERROR, "Task[%ll] status error in clean up step", taskID, status ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: goto done ; }
Status SortKeyGenerator::getSortKey(const WorkingSetMember& member, BSONObj* objOut) const { StatusWith<BSONObj> sortKey = BSONObj(); if (member.hasObj()) { sortKey = getSortKeyFromObject(member); } else { sortKey = getSortKeyFromIndexKey(member); } if (!sortKey.isOK()) { return sortKey.getStatus(); } if (!_sortHasMeta) { *objOut = sortKey.getValue(); return Status::OK(); } BSONObjBuilder mergedKeyBob; // Merge metadata into the key. BSONObjIterator it(_rawSortSpec); BSONObjIterator sortKeyIt(sortKey.getValue()); while (it.more()) { BSONElement elt = it.next(); if (elt.isNumber()) { // Merge btree key elt. mergedKeyBob.append(sortKeyIt.next()); } else if (LiteParsedQuery::isTextScoreMeta(elt)) { // Add text score metadata double score = 0.0; if (member.hasComputed(WSM_COMPUTED_TEXT_SCORE)) { const TextScoreComputedData* scoreData = static_cast<const TextScoreComputedData*>( member.getComputed(WSM_COMPUTED_TEXT_SCORE)); score = scoreData->getScore(); } mergedKeyBob.append("$metaTextScore", score); } } *objOut = mergedKeyBob.obj(); return Status::OK(); }
void BSONElementHasher::recursiveHash( Hasher* h , const BSONElement& e , bool includeFieldName ) { int canonicalType = e.canonicalType(); h->addData( &canonicalType , sizeof( canonicalType ) ); if ( includeFieldName ){ h->addData( e.fieldName() , e.fieldNameSize() ); } if ( !e.mayEncapsulate() ){ //if there are no embedded objects (subobjects or arrays), //compute the hash, squashing numeric types to 64-bit ints if ( e.isNumber() ){ long long int i = e.safeNumberLong(); //well-defined for troublesome doubles h->addData( &i , sizeof( i ) ); } else { h->addData( e.value() , e.valuesize() ); } } else { //else identify the subobject. //hash any preceding stuff (in the case of codeWscope) //then each sub-element //then finish with the EOO element. BSONObj b; if ( e.type() == CodeWScope ) { h->addData( e.codeWScopeCode() , e.codeWScopeCodeLen() ); b = e.codeWScopeObject(); } else { b = e.embeddedObject(); } BSONObjIterator i(b); while( i.moreWithEOO() ) { BSONElement el = i.next(); recursiveHash( h , el , true ); } } }
static bool isLegacyCenterSphere(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } bool isCenterSphere = mongoutils::str::equals(type.fieldName(), "$centerSphere"); if (!isCenterSphere) { return false; } BSONObjIterator objIt(type.embeddedObject()); BSONElement center = objIt.next(); if (!center.isABSONObj()) { return false; } if (!isLegacyPoint(center.Obj())) { return false; } // Check to make sure the points are valid lng/lat. BSONObjIterator coordIt(center.Obj()); BSONElement lng = coordIt.next(); BSONElement lat = coordIt.next(); if (!isValidLngLat(lng.Number(), lat.Number())) { return false; } if (!objIt.more()) { return false; } BSONElement radius = objIt.next(); if (!radius.isNumber()) { return false; } return true; }
INT32 catSplitFinish( const BSONObj & splitInfo, pmdEDUCB * cb, INT16 w ) { INT32 rc = SDB_OK ; UINT64 taskID = 0 ; BSONElement ele = splitInfo.getField( CAT_TASKID_NAME ) ; PD_CHECK( ele.isNumber(), SDB_INVALIDARG, error, PDERROR, "Failed to get field[%s], type: %d", CAT_TASKID_NAME, ele.type() ) ; taskID = ( UINT64 )ele.numberLong() ; rc = catRemoveTask( taskID, cb, w ) ; PD_RC_CHECK( rc, PDERROR, "Remove task[%lld] failed, rc: %d", taskID, rc ) ; done: return rc ; error: goto done ; }
Status SortStageKeyGenerator::getSortKey(const WorkingSetMember& member, BSONObj* objOut) const { BSONObj btreeKeyToUse; Status btreeStatus = getBtreeKey(member.obj, &btreeKeyToUse); if (!btreeStatus.isOK()) { return btreeStatus; } if (!_sortHasMeta) { *objOut = btreeKeyToUse; return Status::OK(); } BSONObjBuilder mergedKeyBob; // Merge metadata into the key. BSONObjIterator it(_rawSortSpec); BSONObjIterator btreeIt(btreeKeyToUse); while (it.more()) { BSONElement elt = it.next(); if (elt.isNumber()) { // Merge btree key elt. mergedKeyBob.append(btreeIt.next()); } else if (LiteParsedQuery::isTextScoreMeta(elt)) { // Add text score metadata double score = 0.0; if (member.hasComputed(WSM_COMPUTED_TEXT_SCORE)) { const TextScoreComputedData* scoreData = static_cast<const TextScoreComputedData*>( member.getComputed(WSM_COMPUTED_TEXT_SCORE)); score = scoreData->getScore(); } mergedKeyBob.append("$metaTextScore", score); } } *objOut = mergedKeyBob.obj(); return Status::OK(); }
Status Command::parseCommandCursorOptions(const BSONObj& cmdObj, long long defaultBatchSize, long long* batchSize) { invariant(batchSize); *batchSize = defaultBatchSize; BSONElement cursorElem = cmdObj["cursor"]; if (cursorElem.eoo()) { return Status::OK(); } if (cursorElem.type() != mongo::Object) { return Status(ErrorCodes::TypeMismatch, "cursor field must be missing or an object"); } BSONObj cursor = cursorElem.embeddedObject(); BSONElement batchSizeElem = cursor["batchSize"]; const int expectedNumberOfCursorFields = batchSizeElem.eoo() ? 0 : 1; if (cursor.nFields() != expectedNumberOfCursorFields) { return Status(ErrorCodes::BadValue, "cursor object can't contain fields other than batchSize"); } if (batchSizeElem.eoo()) { return Status::OK(); } if (!batchSizeElem.isNumber()) { return Status(ErrorCodes::TypeMismatch, "cursor.batchSize must be a number"); } // This can change in the future, but for now all negatives are reserved. if (batchSizeElem.numberLong() < 0) { return Status(ErrorCodes::BadValue, "cursor.batchSize must not be negative"); } *batchSize = batchSizeElem.numberLong(); return Status::OK(); }
FieldParser::FieldState FieldParser::extractNumber(BSONElement elem, const BSONField<double>& field, double* out, string* errMsg) { if (elem.eoo()) { if (field.hasDefault()) { *out = field.getDefault(); return FIELD_DEFAULT; } else { return FIELD_NONE; } } if (elem.isNumber()) { *out = elem.numberDouble(); return FIELD_SET; } _genFieldErrMsg(elem, field, "number", errMsg); return FIELD_INVALID; }
ShardStatus Shard::getStatus() const { BSONObj listDatabases; uassert(28589, str::stream() << "call to listDatabases on " << getConnString().toString() << " failed: " << listDatabases, runCommand("admin", BSON("listDatabases" << 1), listDatabases)); BSONElement totalSizeElem = listDatabases["totalSize"]; uassert(28590, "totalSize field not found in listDatabases", totalSizeElem.isNumber()); BSONObj serverStatus; uassert(28591, str::stream() << "call to serverStatus on " << getConnString().toString() << " failed: " << serverStatus, runCommand("admin", BSON("serverStatus" << 1), serverStatus)); BSONElement versionElement = serverStatus["version"]; uassert(28599, "version field not found in serverStatus", versionElement.type() == String); return ShardStatus(totalSizeElem.numberLong(), versionElement.str()); }
virtual bool run(const string &db, BSONObj &cmdObj, int options, string &errmsg, BSONObjBuilder &result, bool fromRepl) { BSONElement e = cmdObj.firstElement(); long long bps; if (e.type() == String) { Status status = BytesQuantity<long long>::fromString(e.Stringdata(), bps); if (!status.isOK()) { stringstream ss; ss << "error parsing number " << e.Stringdata() << ": " << status.codeString() << " " << status.reason(); errmsg = ss.str(); return false; } } else { if (!e.isNumber()) { errmsg = "backupThrottle argument must be a number"; return false; } bps = e.safeNumberLong(); } return Manager::throttle(bps, errmsg, result); }
// static BSONObj S2AccessMethod::fixSpec(const BSONObj& specObj) { // If the spec object has the field "2dsphereIndexVersion", validate it. If it doesn't, add // {2dsphereIndexVersion: 2}, which is the default for newly-built indexes. BSONElement indexVersionElt = specObj[kIndexVersionFieldName]; if (indexVersionElt.eoo()) { BSONObjBuilder bob; bob.appendElements(specObj); bob.append(kIndexVersionFieldName, S2_INDEX_VERSION_2); return bob.obj(); } const int indexVersion = indexVersionElt.numberInt(); uassert(17394, str::stream() << "unsupported geo index version { " << kIndexVersionFieldName << " : " << indexVersionElt << " }, only support versions: [" << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "]", indexVersionElt.isNumber() && (indexVersion == S2_INDEX_VERSION_2 || indexVersion == S2_INDEX_VERSION_1)); return specObj; }
Status bsonExtractBooleanFieldWithDefault(const BSONObj& object, StringData fieldName, bool defaultValue, bool* out) { BSONElement value; Status status = bsonExtractField(object, fieldName, &value); if (status == ErrorCodes::NoSuchKey) { *out = defaultValue; return Status::OK(); } else if (!status.isOK()) { return status; } else if (!value.isNumber() && !value.isBoolean()) { return Status(ErrorCodes::TypeMismatch, mongoutils::str::stream() << "Expected boolean or number type for field \"" << fieldName << "\", found " << typeName(value.type())); } else { *out = value.trueValue(); return Status::OK(); } }