本文整理汇总了C++中BSONObj::getStringField方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj::getStringField方法的具体用法?C++ BSONObj::getStringField怎么用?C++ BSONObj::getStringField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObj
的用法示例。
在下文中一共展示了BSONObj::getStringField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
virtual bool run(OperationContext* txn,
const string&,
BSONObj& cmdObj,
int,
string& errmsg,
BSONObjBuilder& result) {
string fromhost = cmdObj.getStringField("fromhost");
if (fromhost.empty()) {
/* copy from self */
stringstream ss;
ss << "localhost:" << serverGlobalParams.port;
fromhost = ss.str();
}
const ConnectionString cs(uassertStatusOK(ConnectionString::parse(fromhost)));
auto& authConn = CopyDbAuthConnection::forClient(txn->getClient());
authConn.reset(cs.connect(errmsg));
if (!authConn) {
return false;
}
BSONObj ret;
if (!authConn->runCommand("admin", BSON("getnonce" << 1), ret)) {
errmsg = "couldn't get nonce " + ret.toString();
authConn.reset();
return false;
}
result.appendElements(ret);
return true;
}
示例2: getMissingDoc
BSONObj Sync::getMissingDoc(const BSONObj& o) {
OplogReader missingObjReader;
const char *ns = o.getStringField("ns");
// capped collections
NamespaceDetails *nsd = nsdetails(ns);
if ( nsd && nsd->isCapped() ) {
log() << "replication missing doc, but this is okay for a capped collection (" << ns << ")" << endl;
return BSONObj();
}
uassert(15916, str::stream() << "Can no longer connect to initial sync source: " << hn, missingObjReader.connect(hn));
// might be more than just _id in the update criteria
BSONObj query = BSONObjBuilder().append(o.getObjectField("o2")["_id"]).obj();
BSONObj missingObj;
try {
missingObj = missingObjReader.findOne(ns, query);
} catch(DBException& e) {
log() << "replication assertion fetching missing object: " << e.what() << endl;
throw;
}
return missingObj;
}
示例3: BSON
void CMISProductNotificationAPI::Convert2JSON(CNotificationModel* pData, BSONObj &boRecord)
{
//{"data":[{"request_code":"RP130314/004","operation_department":"BO6"}],"source":"SDK"}
BSONArrayBuilder babElement;
BSONObjBuilder bobProductInfo;
map<string, string>::iterator mit;
map<string, string> mapAPIField;
mapAPIField["department_alias"] = "operation_department";
mapAPIField["request_code"] = "request_code";
BSONObj boTemp = *pData;
for (mit = mapAPIField.begin(); mit != mapAPIField.end(); mit++)
{
if (boTemp.hasField(mit->first)){
bobProductInfo.append(mit->second, boTemp.getStringField(mit->first.c_str()));
}
else{
bobProductInfo.append(mit->second, "");
}
}
babElement << bobProductInfo.obj();
boRecord = BSON(
"data" << babElement.arr() <<
"source" << "SDK"
);
}
示例4: getUserObj
bool CmdAuthenticate::getUserObj(const string& dbname, const string& user, BSONObj& userObj, string& pwd) {
if (user == internalSecurity.user) {
pwd = internalSecurity.pwd;
}
else {
string systemUsers = dbname + ".system.users";
DBConfigPtr config = grid.getDBConfig( systemUsers );
Shard s = config->getShard( systemUsers );
static BSONObj userPattern = BSON("user" << 1);
ShardConnection conn( s, systemUsers );
OCCASIONALLY conn->ensureIndex(systemUsers, userPattern, false, "user_1");
{
BSONObjBuilder b;
b << "user" << user;
BSONObj query = b.done();
userObj = conn->findOne(systemUsers, query);
if( userObj.isEmpty() ) {
log() << "auth: couldn't find user " << user << ", " << systemUsers << endl;
return false;
}
}
pwd = userObj.getStringField("pwd");
}
return true;
}
示例5: getMissingDoc
BSONObj SyncTail::getMissingDoc(OperationContext* txn, Database* db, const BSONObj& o) {
OplogReader missingObjReader; // why are we using OplogReader to run a non-oplog query?
const char* ns = o.getStringField("ns");
// capped collections
Collection* collection = db->getCollection(ns);
if (collection && collection->isCapped()) {
log() << "missing doc, but this is okay for a capped collection (" << ns << ")";
return BSONObj();
}
const int retryMax = 3;
for (int retryCount = 1; retryCount <= retryMax; ++retryCount) {
if (retryCount != 1) {
// if we are retrying, sleep a bit to let the network possibly recover
sleepsecs(retryCount * retryCount);
}
try {
bool ok = missingObjReader.connect(HostAndPort(_hostname));
if (!ok) {
warning() << "network problem detected while connecting to the "
<< "sync source, attempt " << retryCount << " of " << retryMax << endl;
continue; // try again
}
} catch (const SocketException&) {
warning() << "network problem detected while connecting to the "
<< "sync source, attempt " << retryCount << " of " << retryMax << endl;
continue; // try again
}
// get _id from oplog entry to create query to fetch document.
const BSONElement opElem = o.getField("op");
const bool isUpdate = !opElem.eoo() && opElem.str() == "u";
const BSONElement idElem = o.getObjectField(isUpdate ? "o2" : "o")["_id"];
if (idElem.eoo()) {
severe() << "cannot fetch missing document without _id field: " << o.toString();
fassertFailedNoTrace(28742);
}
BSONObj query = BSONObjBuilder().append(idElem).obj();
BSONObj missingObj;
try {
missingObj = missingObjReader.findOne(ns, query);
} catch (const SocketException&) {
warning() << "network problem detected while fetching a missing document from the "
<< "sync source, attempt " << retryCount << " of " << retryMax << endl;
continue; // try again
} catch (DBException& e) {
error() << "assertion fetching missing object: " << e.what() << endl;
throw;
}
// success!
return missingObj;
}
// retry count exceeded
msgasserted(15916,
str::stream() << "Can no longer connect to initial sync source: " << _hostname);
}
示例6: shouldRetry
bool Sync::shouldRetry(const BSONObj& o) {
// should already have write lock
const char *ns = o.getStringField("ns");
Client::Context ctx(ns);
// we don't have the object yet, which is possible on initial sync. get it.
log() << "replication info adding missing object" << endl; // rare enough we can log
BSONObj missingObj = getMissingDoc(o);
if( missingObj.isEmpty() ) {
log() << "replication missing object not found on source. presumably deleted later in oplog" << endl;
log() << "replication o2: " << o.getObjectField("o2").toString() << endl;
log() << "replication o firstfield: " << o.getObjectField("o").firstElementFieldName() << endl;
return false;
}
else {
Collection* collection = ctx.db()->getOrCreateCollection( ns );
verify( collection ); // should never happen
StatusWith<DiskLoc> result = collection->insertDocument( missingObj, true );
uassert(15917,
str::stream() << "failed to insert missing doc: " << result.toString(),
result.isOK() );
LOG(1) << "replication inserted missing doc: " << missingObj.toString() << endl;
return true;
}
}
示例7: UpdateAlertStatus
void CUpdateAlertSttProcessor::UpdateAlertStatus(AlertInfo sAlertInf)
{
string strCurrStatus, strTicketId, strItsmId, strLog;
int iItsmSttNoti;
BSONObj boRecord;
auto_ptr<DBClientCursor> ptrResultCursor = auto_ptr<DBClientCursor>();
m_pAlertModel->Load(sAlertInf);
if (m_pAlertController->Find(ptrResultCursor, m_pAlertModel->GetObjectIdQuery())){
if (ptrResultCursor->more())
{
boRecord = ptrResultCursor->nextSafe();
m_pAlertModel->Load(boRecord);
// ============================Outage-End is empty==========================
if (m_pAlertController->UpdateINCStatus(m_pAlertModel->GetRecordBson())) // API Update Status from Inc
{
m_pAlertController->Update(m_pAlertModel->GetAlertStatus(), m_pAlertModel->GetObjectIdQuery());
strCurrStatus = boRecord.hasField("itsm_status") ? boRecord.getStringField("itsm_status") : "";
strLog = CUtilities::FormatLog(INFO_MSG, "UpdateAlertStt", "ProcessCSUpdate_Call_API", sAlertInf.strSourceId + ": " +
strCurrStatus + " -> " + sAlertInf.strStatus);
CUtilities::WriteInfoLog(INFO_MSG, strLog);
}
}
}
}
示例8: printIfAge
void printIfAge(DBClientConnection& c, int age) {
auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", QUERY( "age" << age ).sort("name") );
while( cursor->more() ) {
BSONObj p = cursor->next();
cout << p.getStringField("name") << endl;
}
}
示例9: unserialize
void DBConfig::unserialize(const BSONObj& from){
_name = from.getStringField("name");
_partitioned = from.getBoolField("partitioned");
_primary = from.getStringField("primary");
_sharded.clear();
BSONObj sharded = from.getObjectField( "sharded" );
if ( ! sharded.isEmpty() ){
BSONObjIterator i(sharded);
while ( i.more() ){
BSONElement e = i.next();
uassert( "sharded things have to be objects" , e.type() == Object );
_sharded[e.fieldName()] = e.embeddedObject();
}
}
}
示例10: run
virtual bool run(OperationContext* txn,
const string&,
BSONObj& cmdObj,
int,
string& errmsg,
BSONObjBuilder& result,
bool fromRepl) {
string fromhost = cmdObj.getStringField("fromhost");
if (fromhost.empty()) {
/* copy from self */
stringstream ss;
ss << "localhost:" << serverGlobalParams.port;
fromhost = ss.str();
}
BSONObj ret;
ConnectionString cs = ConnectionString::parse(fromhost, errmsg);
if (!cs.isValid()) {
return false;
}
authConn_.reset(cs.connect(errmsg));
if (!authConn_.get()) {
return false;
}
if (!authConn_->runCommand("admin", BSON("getnonce" << 1), ret)) {
errmsg = "couldn't get nonce " + ret.toString();
return false;
}
result.appendElements(ret);
return true;
}
示例11: shouldRetry
bool Sync::shouldRetry(const BSONObj& o) {
// should already have write lock
const char *ns = o.getStringField("ns");
Client::Context ctx(ns);
// we don't have the object yet, which is possible on initial sync. get it.
log() << "replication info adding missing object" << endl; // rare enough we can log
BSONObj missingObj = getMissingDoc(o);
if( missingObj.isEmpty() ) {
log() << "replication missing object not found on source. presumably deleted later in oplog" << endl;
log() << "replication o2: " << o.getObjectField("o2").toString() << endl;
log() << "replication o firstfield: " << o.getObjectField("o").firstElementFieldName() << endl;
return false;
}
else {
DiskLoc d = theDataFileMgr.insert(ns, (void*) missingObj.objdata(), missingObj.objsize());
uassert(15917, "Got bad disk location when attempting to insert", !d.isNull());
LOG(1) << "replication inserted missing doc: " << missingObj.toString() << endl;
return true;
}
}
示例12: run
virtual bool run(OperationContext* txn,
const string&,
BSONObj& cmdObj,
int,
string& errmsg,
BSONObjBuilder& result) {
const string fromDb = cmdObj.getStringField("fromdb");
string fromHost = cmdObj.getStringField("fromhost");
if (fromHost.empty()) {
/* copy from self */
stringstream ss;
ss << "localhost:" << serverGlobalParams.port;
fromHost = ss.str();
}
const ConnectionString cs(uassertStatusOK(ConnectionString::parse(fromHost)));
BSONElement mechanismElement;
Status status = bsonExtractField(cmdObj, saslCommandMechanismFieldName, &mechanismElement);
if (!status.isOK()) {
return appendCommandStatus(result, status);
}
BSONElement payloadElement;
status = bsonExtractField(cmdObj, saslCommandPayloadFieldName, &payloadElement);
if (!status.isOK()) {
log() << "Failed to extract payload: " << status;
return false;
}
auto& authConn = CopyDbAuthConnection::forClient(txn->getClient());
authConn.reset(cs.connect(StringData(), errmsg));
if (!authConn.get()) {
return false;
}
BSONObj ret;
if (!authConn->runCommand(
fromDb, BSON("saslStart" << 1 << mechanismElement << payloadElement), ret)) {
authConn.reset();
return appendCommandStatus(result, getStatusFromCommandResult(ret));
}
result.appendElements(ret);
return true;
}
示例13: run
bool run(OperationContext* opCtx,
const std::string& ns,
const BSONObj& cmdObj,
BSONObjBuilder& result) {
log() << "test only command sleep invoked";
long long millis = 0;
if (cmdObj["secs"] || cmdObj["seconds"] || cmdObj["millis"]) {
uassert(51153,
"Only one of 'secs' and 'seconds' may be specified",
!(cmdObj["secs"] && cmdObj["seconds"]));
if (auto secsElem = cmdObj["secs"]) {
uassert(34344, "'secs' must be a number.", secsElem.isNumber());
millis += secsElem.numberLong() * 1000;
} else if (auto secondsElem = cmdObj["seconds"]) {
uassert(51154, "'seconds' must be a number.", secondsElem.isNumber());
millis += secondsElem.numberLong() * 1000;
}
if (auto millisElem = cmdObj["millis"]) {
uassert(34345, "'millis' must be a number.", millisElem.isNumber());
millis += millisElem.numberLong();
}
} else {
millis = 10 * 1000;
}
StringData lockTarget;
if (cmdObj["lockTarget"]) {
lockTarget = cmdObj["lockTarget"].checkAndGetStringData();
}
if (!cmdObj["lock"]) {
// Legacy implementation
if (cmdObj.getBoolField("w")) {
_sleepInLock(opCtx, millis, MODE_X, lockTarget);
} else {
_sleepInLock(opCtx, millis, MODE_S, lockTarget);
}
} else {
uassert(34346, "Only one of 'w' and 'lock' may be set.", !cmdObj["w"]);
std::string lock(cmdObj.getStringField("lock"));
if (lock == "none") {
opCtx->sleepFor(Milliseconds(millis));
} else if (lock == "w") {
_sleepInLock(opCtx, millis, MODE_X, lockTarget);
} else {
uassert(34347, "'lock' must be one of 'r', 'w', 'none'.", lock == "r");
_sleepInLock(opCtx, millis, MODE_S, lockTarget);
}
}
// Interrupt point for testing (e.g. maxTimeMS).
opCtx->checkForInterrupt();
return true;
}
示例14: toStatusString
// static
std::string WorkingSetCommon::toStatusString(const BSONObj& obj) {
if (!isValidStatusMemberObject(obj)) {
Status unknownStatus(ErrorCodes::UnknownError, "no details available");
return unknownStatus.toString();
}
Status status(ErrorCodes::fromInt(obj.getIntField("code")), obj.getStringField("errmsg"));
return status.toString();
}
示例15: run
bool run(const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
string from = jsobj.getStringField( "cloneCollectionAsCapped" );
string to = jsobj.getStringField( "toCollection" );
double size = jsobj.getField( "size" ).number();
bool temp = jsobj.getField( "temp" ).trueValue();
if ( from.empty() || to.empty() || size == 0 ) {
errmsg = "invalid command spec";
return false;
}
Lock::DBWrite dbXLock(dbname);
Client::Context ctx(dbname);
Status status = cloneCollectionAsCapped( ctx.db(), from, to, size, temp, true );
return appendCommandStatus( result, status );
}