当前位置: 首页>>代码示例>>C++>>正文


C++ BSONElement::toString方法代码示例

本文整理汇总了C++中BSONElement::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::toString方法的具体用法?C++ BSONElement::toString怎么用?C++ BSONElement::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BSONElement的用法示例。


在下文中一共展示了BSONElement::toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: isLoopClosed

static Status isLoopClosed(const vector<S2Point>& loop, const BSONElement loopElt) {
    if (loop.empty()) {
        return BAD_VALUE("Loop has no vertices: " << loopElt.toString(false));
    }

    if (loop[0] != loop[loop.size() - 1]) {
        return BAD_VALUE("Loop is not closed: " << loopElt.toString(false));
    }

    return Status::OK();
}
开发者ID:Andiry,项目名称:mongo,代码行数:11,代码来源:geoparser.cpp

示例2: csvString

    // Gets the string representation of a BSON object that can be correctly written to a CSV file
    string csvString (const BSONElement& object) {
        const char* binData; // Only used with BinData type

        switch (object.type()) {
        case MinKey:
            return "$MinKey";
        case MaxKey:
            return "$MaxKey";
        case NumberInt:
        case NumberDouble:
        case NumberLong:
        case Bool:
            return object.toString(false);
        case String:
        case Symbol:
            return csvEscape(object.toString(false), true);
        case Object:
            return csvEscape(object.jsonString(Strict, false));
        case Array:
            return csvEscape(object.jsonString(Strict, false));
        case BinData:
            int len;
            binData = object.binDataClean(len);
            return toHex(binData, len);
        case jstOID:
            return "ObjectID(" + object.OID().toString() + ")"; // OIDs are always 24 bytes
        case Date:
            return timeToISOString(object.Date() / 1000);
        case Timestamp:
            return csvEscape(object.jsonString(Strict, false));
        case RegEx:
            return csvEscape("/" + string(object.regex()) + "/" + string(object.regexFlags()));
        case Code:
            return csvEscape(object.toString(false));
        case CodeWScope:
            if (string(object.codeWScopeScopeDataUnsafe()) == "") {
                return csvEscape(object.toString(false));
            } else {
                return csvEscape(object.jsonString(Strict, false));
            }
        case EOO:
        case Undefined:
        case DBRef:
        case jstNULL:
            cerr << "Invalid BSON object type for CSV output: " << object.type() << endl;
            return "";
        }
        // Can never get here
        verify(false);
        return "";
    }
开发者ID:abhishekkumar1989,项目名称:mongo,代码行数:52,代码来源:export.cpp

示例3: obj

TEST(generator, test1)
{
//   const CHAR *js = "{a:[{c:[{d:{e:[1,2]}}, {d:\"abc\"}]}, {c:[{d:{e:[5,6]}}, {d:{e:[7,8]}}]}], b:10}" ;
   {
   const CHAR *js = "{no:1,name:\"A\",age:2,array1:[{array2:[{array3:[{array4:[\"array5\",\"temp4\"]},\"temp3\"]},\"temp2\"]},\"temp1\"]}"; 
   CHAR *raw = NULL ;
   getBSONRaw( js, &raw ) ;
   ASSERT_TRUE( NULL != raw ) ;
   BSONObj obj( raw ) ;
   BSONObj keyDef = BSON("array1.array2.array3.array4.1" << 1 ) ;
   _ixmIndexKeyGen gen( keyDef ) ;
   Ordering order(Ordering::make(keyDef)) ;
   BSONObjSet keySet( keyDef ) ;
   BSONElement arr ;
   INT32 rc = SDB_OK ;
   rc = gen.getKeys( obj, keySet, &arr ) ;
   ASSERT_TRUE( SDB_OK == rc ) ;
   for ( BSONObjSet::const_iterator itr = keySet.begin() ;
         itr != keySet.end() ;
         itr++ )
   {
      cout << itr->toString() << endl ;
   }

   cout << "arr:" << arr.toString( true, true )  << endl ;
   }
}
开发者ID:Andrew8305,项目名称:SequoiaDB,代码行数:27,代码来源:generator.cpp

示例4: DocumentSourceFacet

intrusive_ptr<DocumentSource> DocumentSourceFacet::createFromBson(
    BSONElement elem, const intrusive_ptr<ExpressionContext>& expCtx) {

    std::vector<FacetPipeline> facetPipelines;
    for (auto&& rawFacet : extractRawPipelines(elem)) {
        const auto facetName = rawFacet.first;

        auto pipeline = uassertStatusOK(Pipeline::parse(rawFacet.second, expCtx));

        uassert(40172,
                str::stream() << "sub-pipeline in $facet stage cannot be empty: " << facetName,
                !pipeline->getSources().empty());

        // Disallow any stages that need to be the first stage in the pipeline.
        for (auto&& stage : pipeline->getSources()) {
            if (stage->isValidInitialSource()) {
                uasserted(40173,
                          str::stream() << stage->getSourceName()
                                        << " is not allowed to be used within a $facet stage: "
                                        << elem.toString());
            }
        }

        facetPipelines.emplace_back(facetName, std::move(pipeline));
    }

    return new DocumentSourceFacet(std::move(facetPipelines), expCtx);
}
开发者ID:ksuarz,项目名称:mongo,代码行数:28,代码来源:document_source_facet.cpp

示例5: i

    S2AccessMethod::S2AccessMethod(IndexCatalogEntry* btreeState, RecordStore* rs)
        : BtreeBasedAccessMethod(btreeState, rs) {

        const IndexDescriptor* descriptor = btreeState->descriptor();

        ExpressionParams::parse2dsphereParams(descriptor->infoObj(),
                                              &_params);

        int geoFields = 0;

        // Categorize the fields we're indexing and make sure we have a geo field.
        BSONObjIterator i(descriptor->keyPattern());
        while (i.more()) {
            BSONElement e = i.next();
            if (e.type() == String && IndexNames::GEO_2DSPHERE == e.String() ) {
                ++geoFields;
            }
            else {
                // We check for numeric in 2d, so that's the check here
                uassert( 16823, (string)"Cannot use " + IndexNames::GEO_2DSPHERE +
                                    " index with other special index types: " + e.toString(),
                         e.isNumber() );
            }
        }

        uassert(16750, "Expect at least one geo field, spec=" + descriptor->keyPattern().toString(),
                geoFields >= 1);

        if (descriptor->isSparse()) {
            warning() << "Sparse option ignored for index spec "
                      << descriptor->keyPattern().toString() << "\n";
        }
    }
开发者ID:Albert-B-P,项目名称:mongo,代码行数:33,代码来源:s2_access_method.cpp

示例6: getLastError

 string DBClientWithCommands::getLastError() { 
     BSONObj info = getLastErrorDetailed();
     BSONElement e = info["err"];
     if( e.eoo() ) return "";
     if( e.type() == Object ) return e.toString();
     return e.str();
 }
开发者ID:jamesgolick,项目名称:mongo,代码行数:7,代码来源:dbclient.cpp

示例7: _getSvcNameFromArg

   const CHAR* _omAgentNodeMgr::_getSvcNameFromArg( const CHAR * arg )
   {
      const CHAR *pSvcName = NULL ;

      try
      {
         BSONObj objArg1( arg ) ;
         BSONElement e = objArg1.getField( PMD_OPTION_SVCNAME ) ;
         if ( e.type() != String )
         {
            PD_LOG( PDERROR, "Param[%s] type[%s] error: %s",
                    PMD_OPTION_SVCNAME, e.type(), e.toString().c_str() ) ;
            goto error ;
         }
         pSvcName = e.valuestrsafe() ;
      }
      catch( std::exception &e )
      {
         PD_LOG( PDERROR, "Ocuur exception: %s", e.what() ) ;
         goto error ;
      }

   done:
      return pSvcName ;
   error:
      goto done ;
   }
开发者ID:hanjirui,项目名称:SequoiaDB,代码行数:27,代码来源:omagentNodeMgr.cpp

示例8: getStatusFromCommandResult

Status getStatusFromCommandResult(const BSONObj& result) {
    BSONElement okElement = result["ok"];
    BSONElement codeElement = result["code"];
    BSONElement errmsgElement = result["errmsg"];

    // StaleConfigException doesn't pass "ok" in legacy servers
    BSONElement dollarErrElement = result["$err"];

    if (okElement.eoo() && dollarErrElement.eoo()) {
        return Status(ErrorCodes::CommandResultSchemaViolation,
                      mongoutils::str::stream() << "No \"ok\" field in command result " << result);
    }
    if (okElement.trueValue()) {
        return Status::OK();
    }
    int code = codeElement.numberInt();
    if (0 == code) {
        code = ErrorCodes::UnknownError;
    }
    std::string errmsg;
    if (errmsgElement.type() == String) {
        errmsg = errmsgElement.String();
    } else if (!errmsgElement.eoo()) {
        errmsg = errmsgElement.toString();
    }

    // we can't use startsWith(errmsg, "no such")
    // as we have errors such as "no such collection"
    if (code == ErrorCodes::UnknownError &&
        (str::startsWith(errmsg, "no such cmd") || str::startsWith(errmsg, "no such command"))) {
        code = ErrorCodes::CommandNotFound;
    }

    return Status(ErrorCodes::Error(code), errmsg, result);
}
开发者ID:ShaneHarvey,项目名称:mongo,代码行数:35,代码来源:get_status_from_command_result.cpp

示例9: toString

    string BSONObj::toString() const {
        if ( isEmpty() ) return "{}";

        stringstream s;
        s << "{ ";
        BSONObjIterator i(*this);
        bool first = true;
        while ( 1 ) {
            massert( "Object does not end with EOO", i.more() );
            BSONElement e = i.next( true );
            massert( "Invalid element size", e.size() > 0 );
            massert( "Element too large", e.size() < ( 1 << 30 ) );
            int offset = e.rawdata() - this->objdata();
            massert( "Element extends past end of object",
                    e.size() + offset <= this->objsize() );
            e.validate();
            bool end = ( e.size() + offset == this->objsize() );
            if ( e.eoo() ) {
                massert( "EOO Before end of object", end );
                break;
            }
            if ( first )
                first = false;
            else
                s << ", ";
            s << e.toString();
        }
        s << " }";
        return s.str();
    }
开发者ID:agiamas,项目名称:mongo,代码行数:30,代码来源:jsobj.cpp

示例10: getLastError

 string DBClientWithCommands::getLastError() { 
     BSONObj info;
     runCommand("admin", getlasterrorcmdobj, info);
     BSONElement e = info["err"];
     if( e.eoo() ) return "";
     if( e.type() == Object ) return e.toString();
     return e.str();
 }
开发者ID:tanfulai,项目名称:mongo,代码行数:8,代码来源:dbclient.cpp

示例11: parseBigSimplePolygonCoordinates

static Status parseBigSimplePolygonCoordinates(const BSONElement& elem, BigSimplePolygon* out) {
    if (Array != elem.type())
        return BAD_VALUE("Coordinates of polygon must be an array");


    const vector<BSONElement>& coordinates = elem.Array();
    // Only one loop is allowed in a BigSimplePolygon
    if (coordinates.size() != 1) {
        return BAD_VALUE(
            "Only one simple loop is allowed in a big polygon: " << elem.toString(false));
    }

    vector<S2Point> exteriorVertices;
    Status status = Status::OK();
    string err;

    status = parseArrayOfCoordinates(coordinates.front(), &exteriorVertices);
    if (!status.isOK())
        return status;

    status = isLoopClosed(exteriorVertices, coordinates.front());
    if (!status.isOK())
        return status;

    eraseDuplicatePoints(&exteriorVertices);

    // The last point is duplicated.  We drop it, since S2Loop expects no
    // duplicate points
    exteriorVertices.resize(exteriorVertices.size() - 1);

    // At least 3 vertices.
    if (exteriorVertices.size() < 3) {
        return BAD_VALUE("Loop must have at least 3 different vertices: " << elem.toString(false));
    }

    unique_ptr<S2Loop> loop(new S2Loop(exteriorVertices));
    // Check whether this loop is valid.
    if (!loop->IsValid(&err)) {
        return BAD_VALUE("Loop is not valid: " << elem.toString(false) << " " << err);
    }

    out->Init(loop.release());
    return Status::OK();
}
开发者ID:Andiry,项目名称:mongo,代码行数:44,代码来源:geoparser.cpp

示例12: parseNsFullyQualified

 string Command::parseNsFullyQualified(const string& dbname, const BSONObj& cmdObj) const {
     BSONElement first = cmdObj.firstElement();
     uassert(17005,
             mongoutils::str::stream() << "Main argument to " << first.fieldNameStringData() <<
                     " must be a fully qualified namespace string.  Found: " <<
                     first.toString(false),
             first.type() == mongo::String &&
             NamespaceString::validCollectionComponent(first.valuestr()));
     return first.String();
 }
开发者ID:wjin,项目名称:mongo,代码行数:10,代码来源:commands.cpp

示例13: if

   static INT32 _rtnParseQueryMeta( const BSONObj &meta, const CHAR *&scanType,
                                    const CHAR *&indexName, INT32 &indexLID,
                                    INT32 &direction, BSONObj &blockObj )
   {
      INT32 rc = SDB_OK ;
      BSONElement ele ;

      rc = rtnGetStringElement( meta, FIELD_NAME_SCANTYPE, &scanType ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d",
                   FIELD_NAME_SCANTYPE, rc ) ;

      if ( 0 == ossStrcmp( scanType, VALUE_NAME_IXSCAN ) )
      {
         ele = meta.getField( FIELD_NAME_INDEXBLOCKS ) ;

         rc = rtnGetStringElement( meta, FIELD_NAME_INDEXNAME, &indexName ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d",
                      FIELD_NAME_INDEXNAME, rc ) ;

         rc = rtnGetIntElement( meta, FIELD_NAME_INDEXLID, indexLID ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d",
                      FIELD_NAME_INDEXLID, rc ) ;

         rc = rtnGetIntElement( meta, FIELD_NAME_DIRECTION, direction ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d",
                      FIELD_NAME_DIRECTION, rc ) ;
      }
      else if ( 0 == ossStrcmp( scanType, VALUE_NAME_TBSCAN ) )
      {
         ele = meta.getField( FIELD_NAME_DATABLOCKS ) ;
      }
      else
      {
         PD_LOG( PDERROR, "Query meta[%s] scan type error",
                 meta.toString().c_str() ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }

      if ( Array != ele.type() )
      {
         PD_LOG( PDERROR, "Block field[%s] type error",
                 ele.toString().c_str() ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }
      blockObj = ele.embeddedObject() ;

   done:
      return rc ;
   error:
      goto done ;
   }
开发者ID:jasonsungblog,项目名称:SequoiaDB,代码行数:53,代码来源:rtnQuery.cpp

示例14: apply

Status ModifierObjectReplace::apply() const {
    dassert(!_preparedState->noOp);

    // Remove the contents of the provided doc.
    mutablebson::Document& doc = _preparedState->doc;
    mutablebson::Element current = doc.root().leftChild();
    mutablebson::Element srcIdElement = doc.end();
    while (current.ok()) {
        mutablebson::Element toRemove = current;
        current = current.rightSibling();

        // Skip _id field element -- it should not change
        if (toRemove.getFieldName() == idFieldName) {
            srcIdElement = toRemove;
            continue;
        }

        Status status = toRemove.remove();
        if (!status.isOK()) {
            return status;
        }
    }

    // Insert the provided contents instead.
    BSONElement dstIdElement;
    BSONObjIterator it(_val);
    while (it.more()) {
        BSONElement elem = it.next();
        if (elem.fieldNameStringData() == idFieldName) {
            dstIdElement = elem;

            // Do not duplicate _id field
            if (srcIdElement.ok()) {
                if (srcIdElement.compareWithBSONElement(dstIdElement, nullptr, true) != 0) {
                    return Status(ErrorCodes::ImmutableField,
                                  str::stream() << "The _id field cannot be changed from {"
                                                << srcIdElement.toString()
                                                << "} to {"
                                                << dstIdElement.toString()
                                                << "}.");
                }
                continue;
            }
        }

        Status status = doc.root().appendElement(elem);
        if (!status.isOK()) {
            return status;
        }
    }

    return Status::OK();
}
开发者ID:ChineseDr,项目名称:mongo,代码行数:53,代码来源:modifier_object_replace.cpp

示例15: genID

std::string ChunkType::genID(const NamespaceString& nss, const BSONObj& o) {
    StringBuilder buf;
    buf << nss.ns() << "-";

    BSONObjIterator i(o);
    while (i.more()) {
        BSONElement e = i.next();
        buf << e.fieldName() << "_" << e.toString(false, true);
    }

    return buf.str();
}
开发者ID:i80and,项目名称:mongo,代码行数:12,代码来源:type_chunk.cpp


注:本文中的BSONElement::toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。