本文整理汇总了C++中BSONObjBuilder::resetToEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObjBuilder::resetToEmpty方法的具体用法?C++ BSONObjBuilder::resetToEmpty怎么用?C++ BSONObjBuilder::resetToEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObjBuilder
的用法示例。
在下文中一共展示了BSONObjBuilder::resetToEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runCommandDirectly
BSONObj CommandHelpers::runCommandDirectly(OperationContext* opCtx, const OpMsgRequest& request) {
auto command = globalCommandRegistry()->findCommand(request.getCommandName());
invariant(command);
BSONObjBuilder out;
try {
bool ok = command->publicRun(opCtx, request, out);
appendCommandStatus(out, ok);
} catch (const StaleConfigException&) {
// These exceptions are intended to be handled at a higher level.
throw;
} catch (const DBException& ex) {
out.resetToEmpty();
appendCommandStatus(out, ex.toStatus());
}
return out.obj();
}
示例2: execCommandClient
void Command::execCommandClient(OperationContext* txn,
Command* c,
int queryOptions,
const char* ns,
BSONObj& cmdObj,
BSONObjBuilder& result) {
std::string dbname = nsToDatabase(ns);
if (cmdObj.getBoolField("help")) {
stringstream help;
help << "help for: " << c->getName() << " ";
c->help(help);
result.append("help", help.str());
appendCommandStatus(result, true, "");
return;
}
Status status = checkAuthorization(c, txn, dbname, cmdObj);
if (!status.isOK()) {
appendCommandStatus(result, status);
return;
}
c->_commandsExecuted.increment();
if (c->shouldAffectCommandCounter()) {
globalOpCounters.gotCommand();
}
StatusWith<WriteConcernOptions> wcResult =
WriteConcernOptions::extractWCFromCommand(cmdObj, dbname);
if (!wcResult.isOK()) {
appendCommandStatus(result, wcResult.getStatus());
return;
}
bool supportsWriteConcern = c->supportsWriteConcern(cmdObj);
if (!supportsWriteConcern && !wcResult.getValue().usedDefault) {
// This command doesn't do writes so it should not be passed a writeConcern.
// If we did not use the default writeConcern, one was provided when it shouldn't have
// been by the user.
appendCommandStatus(
result, Status(ErrorCodes::InvalidOptions, "Command does not support writeConcern"));
return;
}
// attach tracking
rpc::TrackingMetadata trackingMetadata;
trackingMetadata.initWithOperName(c->getName());
rpc::TrackingMetadata::get(txn) = trackingMetadata;
std::string errmsg;
bool ok = false;
try {
if (!supportsWriteConcern) {
ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
} else {
// Change the write concern while running the command.
const auto oldWC = txn->getWriteConcern();
ON_BLOCK_EXIT([&] { txn->setWriteConcern(oldWC); });
txn->setWriteConcern(wcResult.getValue());
ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
}
} catch (const DBException& e) {
result.resetToEmpty();
const int code = e.getCode();
// Codes for StaleConfigException
if (code == ErrorCodes::RecvStaleConfig || code == ErrorCodes::SendStaleConfig) {
throw;
}
errmsg = e.what();
result.append("code", code);
}
if (!ok) {
c->_commandsFailed.increment();
}
appendCommandStatus(result, ok, errmsg);
}