本文整理汇总了C++中BSONElement::valuestrsafe方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::valuestrsafe方法的具体用法?C++ BSONElement::valuestrsafe怎么用?C++ BSONElement::valuestrsafe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::valuestrsafe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _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 ;
}
示例2: getIdentSize
int64_t WiredTigerUtil::getIdentSize(WT_SESSION* s,
const std::string& uri ) {
BSONObjBuilder b;
Status status = WiredTigerUtil::exportTableToBSON(s,
"statistics:" + uri,
"statistics=(fast)",
&b);
if ( !status.isOK() ) {
if ( status.code() == ErrorCodes::CursorNotFound ) {
// ident gone, so its 0
return 0;
}
uassertStatusOK( status );
}
BSONObj obj = b.obj();
BSONObj sub = obj["block-manager"].Obj();
BSONElement e = sub["file size in bytes"];
invariant( e.type() );
if ( e.isNumber() )
return e.safeNumberLong();
return strtoull( e.valuestrsafe(), NULL, 10 );
}
示例3: onDeleteOp
void CollectionShardingState::onDeleteOp(OperationContext* txn,
const CollectionShardingState::DeleteState& deleteState) {
dassert(txn->lockState()->isCollectionLockedForMode(_nss.ns(), MODE_IX));
if (txn->writesAreReplicated() && serverGlobalParams.clusterRole == ClusterRole::ShardServer &&
_nss == NamespaceString::kConfigCollectionNamespace) {
if (auto idElem = deleteState.idDoc["_id"]) {
uassert(40070,
"cannot delete shardIdentity document while in --shardsvr mode",
idElem.str() != ShardIdentityType::IdName);
}
}
// For backwards compatibility, cancel a pending asynchronous addShard task created on the
// primary config as a result of a 3.2 mongos doing addShard for the shard with id
// deletedDocId.
if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer &&
_nss == ShardType::ConfigNS) {
BSONElement idElement = deleteState.idDoc["_id"];
invariant(!idElement.eoo());
auto shardIdStr = idElement.valuestrsafe();
txn->recoveryUnit()->registerChange(
new RemoveShardLogOpHandler(txn, ShardId(std::move(shardIdStr))));
}
checkShardVersionOrThrow(txn);
if (_sourceMgr && deleteState.isMigrating) {
_sourceMgr->getCloner()->onDeleteOp(txn, deleteState.idDoc);
}
}
示例4: run
void run() {
OperationContextImpl txn;
Client::WriteContext ctx(&txn, _ns);
int numFinishedIndexesStart = _catalog->numIndexesReady(&txn);
Helpers::ensureIndex(&txn, _coll, BSON("x" << 1), false, "_x_0");
Helpers::ensureIndex(&txn, _coll, BSON("y" << 1), false, "_y_0");
ASSERT_TRUE(_catalog->numIndexesReady(&txn) == numFinishedIndexesStart+2);
IndexCatalog::IndexIterator ii = _catalog->getIndexIterator(&txn,false);
int indexesIterated = 0;
bool foundIndex = false;
while (ii.more()) {
IndexDescriptor* indexDesc = ii.next();
indexesIterated++;
BSONObjIterator boit(indexDesc->infoObj());
while (boit.more() && !foundIndex) {
BSONElement e = boit.next();
if (str::equals(e.fieldName(), "name") &&
str::equals(e.valuestrsafe(), "_y_0")) {
foundIndex = true;
break;
}
}
}
ctx.commit();
ASSERT_TRUE(indexesIterated == _catalog->numIndexesReady(&txn));
ASSERT_TRUE(foundIndex);
}
示例5: set
virtual Status set( const BSONElement& newValueElement ) {
if (!theReplSet) {
return Status( ErrorCodes::BadValue, "replication is not enabled" );
}
std::string prefetch = newValueElement.valuestrsafe();
return setFromString( prefetch );
}
示例6: getLanguageToUse
string FTSSpec::getLanguageToUse( const BSONObj& userDoc ) const {
BSONElement e = userDoc[_languageOverrideField];
if ( e.type() == String ) {
const char * x = e.valuestrsafe();
if ( strlen( x ) > 0 )
return x;
}
return _defaultLanguage;
}
示例7: set
virtual Status set(const BSONElement& newValueElement) {
if (getGlobalReplicationCoordinator()->getReplicationMode() !=
ReplicationCoordinator::modeReplSet) {
return Status(ErrorCodes::BadValue, "replication is not enabled");
}
std::string prefetch = newValueElement.valuestrsafe();
return setFromString(prefetch);
}
示例8: dassert
const FTSLanguage& FTSSpec::_getLanguageToUseV1(const BSONObj& userDoc) const {
BSONElement e = userDoc[_languageOverrideField];
if (e.type() == String) {
const char* x = e.valuestrsafe();
if (strlen(x) > 0) {
StatusWithFTSLanguage swl = FTSLanguage::make(x, TEXT_INDEX_VERSION_1);
dassert(swl.isOK()); // make() w/ TEXT_INDEX_VERSION_1 guaranteed to not fail.
return *swl.getValue();
}
}
return *_defaultLanguage;
}
示例9: Status
StatusWith<ParsedDistinct> ParsedDistinct::parse(OperationContext* txn,
const NamespaceString& nss,
const BSONObj& cmdObj,
const ExtensionsCallback& extensionsCallback,
bool isExplain) {
// Extract the key field.
BSONElement keyElt;
auto statusKey = bsonExtractTypedField(cmdObj, kKeyField, BSONType::String, &keyElt);
if (!statusKey.isOK()) {
return {statusKey};
}
auto key = keyElt.valuestrsafe();
auto qr = stdx::make_unique<QueryRequest>(nss);
// Extract the query field. If the query field is nonexistent, an empty query is used.
if (BSONElement queryElt = cmdObj[kQueryField]) {
if (queryElt.type() == BSONType::Object) {
qr->setFilter(queryElt.embeddedObject());
} else if (queryElt.type() != BSONType::jstNULL) {
return Status(ErrorCodes::TypeMismatch,
str::stream() << "\"" << kQueryField << "\" had the wrong type. Expected "
<< typeName(BSONType::Object)
<< " or "
<< typeName(BSONType::jstNULL)
<< ", found "
<< typeName(queryElt.type()));
}
}
// Extract the collation field, if it exists.
if (BSONElement collationElt = cmdObj[kCollationField]) {
if (collationElt.type() != BSONType::Object) {
return Status(ErrorCodes::TypeMismatch,
str::stream() << "\"" << kCollationField
<< "\" had the wrong type. Expected "
<< typeName(BSONType::Object)
<< ", found "
<< typeName(collationElt.type()));
}
qr->setCollation(collationElt.embeddedObject());
}
qr->setExplain(isExplain);
auto cq = CanonicalQuery::canonicalize(txn, std::move(qr), extensionsCallback);
if (!cq.isOK()) {
return cq.getStatus();
}
return ParsedDistinct(std::move(cq.getValue()), std::move(key));
}
示例10: Status
/**
* Used by explain() and run() to get the PlanExecutor for the query.
*/
StatusWith<unique_ptr<PlanExecutor>> getPlanExecutor(OperationContext* txn,
Collection* collection,
const string& ns,
const BSONObj& cmdObj,
bool isExplain) const {
// Extract the key field.
BSONElement keyElt;
auto statusKey = bsonExtractTypedField(cmdObj, kKeyField, BSONType::String, &keyElt);
if (!statusKey.isOK()) {
return {statusKey};
}
string key = keyElt.valuestrsafe();
// Extract the query field. If the query field is nonexistent, an empty query is used.
BSONObj query;
if (BSONElement queryElt = cmdObj[kQueryField]) {
if (queryElt.type() == BSONType::Object) {
query = queryElt.embeddedObject();
} else if (queryElt.type() != BSONType::jstNULL) {
return Status(ErrorCodes::TypeMismatch,
str::stream() << "\"" << kQueryField
<< "\" had the wrong type. Expected "
<< typeName(BSONType::Object) << " or "
<< typeName(BSONType::jstNULL) << ", found "
<< typeName(queryElt.type()));
}
}
// Extract the collation field, if it exists.
// TODO SERVER-23473: Pass this collation spec object down so that it can be converted into
// a CollatorInterface.
BSONObj collation;
if (BSONElement collationElt = cmdObj[kCollationField]) {
if (collationElt.type() != BSONType::Object) {
return Status(ErrorCodes::TypeMismatch,
str::stream() << "\"" << kCollationField
<< "\" had the wrong type. Expected "
<< typeName(BSONType::Object) << ", found "
<< typeName(collationElt.type()));
}
collation = collationElt.embeddedObject();
}
auto executor = getExecutorDistinct(
txn, collection, ns, query, key, isExplain, PlanExecutor::YIELD_AUTO);
if (!executor.isOK()) {
return executor.getStatus();
}
return std::move(executor.getValue());
}
示例11: removeFile
BSONObj removeFile(const BSONObj& args, void* data) {
BSONElement e = singleArg(args);
bool found = false;
boost::filesystem::path root(e.valuestrsafe());
if (boost::filesystem::exists(root)) {
found = true;
boost::filesystem::remove_all(root);
}
BSONObjBuilder b;
b.appendBool("removed", found);
return b.obj();
}
示例12: _checkOperation
/**
* Returns true if 'e' contains a valid operation.
*/
bool _checkOperation(const BSONElement& e, string& errmsg) {
if (e.type() != Object) {
errmsg = str::stream() << "op not an object: " << e.fieldName();
return false;
}
BSONObj obj = e.Obj();
// op - operation type
BSONElement opElement = obj.getField("op");
if (opElement.eoo()) {
errmsg = str::stream()
<< "op does not contain required \"op\" field: " << e.fieldName();
return false;
}
if (opElement.type() != mongol::String) {
errmsg = str::stream() << "\"op\" field is not a string: " << e.fieldName();
return false;
}
// operation type -- see logOp() comments for types
const char* opType = opElement.valuestrsafe();
if (*opType == '\0') {
errmsg = str::stream() << "\"op\" field value cannot be empty: " << e.fieldName();
return false;
}
// ns - namespace
// Only operations of type 'n' are allowed to have an empty namespace.
BSONElement nsElement = obj.getField("ns");
if (nsElement.eoo()) {
errmsg = str::stream()
<< "op does not contain required \"ns\" field: " << e.fieldName();
return false;
}
if (nsElement.type() != mongol::String) {
errmsg = str::stream() << "\"ns\" field is not a string: " << e.fieldName();
return false;
}
if (nsElement.String().find('\0') != std::string::npos) {
errmsg = str::stream() << "namespaces cannot have embedded null characters";
return false;
}
if (*opType != 'n' && nsElement.String().empty()) {
errmsg = str::stream()
<< "\"ns\" field value cannot be empty when op type is not 'n': " << e.fieldName();
return false;
}
return true;
}
示例13: parse
Status WriteConcernOptions::parse(const BSONObj& obj) {
reset();
if (obj.isEmpty()) {
return Status(ErrorCodes::FailedToParse, "write concern object cannot be empty");
}
BSONElement jEl = obj["j"];
if (!jEl.eoo() && !jEl.isNumber() && jEl.type() != Bool) {
return Status(ErrorCodes::FailedToParse, "j must be numeric or a boolean value");
}
const bool j = jEl.trueValue();
BSONElement fsyncEl = obj["fsync"];
if (!fsyncEl.eoo() && !fsyncEl.isNumber() && fsyncEl.type() != Bool) {
return Status(ErrorCodes::FailedToParse, "fsync must be numeric or a boolean value");
}
const bool fsync = fsyncEl.trueValue();
if (j && fsync)
return Status(ErrorCodes::FailedToParse, "fsync and j options cannot be used together");
if (j) {
syncMode = SyncMode::JOURNAL;
} else if (fsync) {
syncMode = SyncMode::FSYNC;
} else if (!jEl.eoo()) {
syncMode = SyncMode::NONE;
}
BSONElement e = obj["w"];
if (e.isNumber()) {
wNumNodes = e.numberInt();
} else if (e.type() == String) {
wMode = e.valuestrsafe();
} else if (e.eoo() || e.type() == jstNULL || e.type() == Undefined) {
wNumNodes = 1;
} else {
return Status(ErrorCodes::FailedToParse, "w has to be a number or a string");
}
wTimeout = obj["wtimeout"].numberInt();
return Status::OK();
}
示例14: cat
BSONObj cat(const BSONObj& args){
BSONElement e = oneArg(args);
stringstream ss;
ifstream f(e.valuestrsafe());
uassert(CANT_OPEN_FILE, "couldn't open file", f.is_open() );
streamsize sz = 0;
while( 1 ) {
char ch = 0;
// slow...maybe change one day
f.get(ch);
if( ch == 0 ) break;
ss << ch;
sz += 1;
uassert(13301, "cat() : file to big to load as a variable", sz < 1024 * 1024 * 16);
}
return BSON( "" << ss.str() );
}
示例15: BSON
BSONObj md5sumFile(const BSONObj& args){
BSONElement e = oneArg(args);
stringstream ss;
FILE* f = fopen(e.valuestrsafe(), "rb");
uassert(CANT_OPEN_FILE, "couldn't open file", f );
md5digest d;
md5_state_t st;
md5_init(&st);
enum {BUFLEN = 4*1024};
char buffer[BUFLEN];
int bytes_read;
while( (bytes_read = fread(buffer, 1, BUFLEN, f)) ) {
md5_append( &st , (const md5_byte_t*)(buffer) , bytes_read );
}
md5_finish(&st, d);
return BSON( "" << digestToString( d ) );
}