本文整理汇总了C++中DatabaseType::toBSON方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseType::toBSON方法的具体用法?C++ DatabaseType::toBSON怎么用?C++ DatabaseType::toBSON使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseType
的用法示例。
在下文中一共展示了DatabaseType::toBSON方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createDatabase
Status CatalogManager::createDatabase(const std::string& dbName) {
invariant(nsIsDbOnly(dbName));
// The admin and config databases should never be explicitly created. They "just exist",
// i.e. getDatabase will always return an entry for them.
invariant(dbName != "admin");
invariant(dbName != "config");
// Lock the database globally to prevent conflicts with simultaneous database creation.
auto scopedDistLock =
getDistLockManager()->lock(dbName, "createDatabase", Seconds{5000}, Milliseconds{500});
if (!scopedDistLock.isOK()) {
return scopedDistLock.getStatus();
}
// check for case sensitivity violations
Status status = _checkDbDoesNotExist(dbName);
if (!status.isOK()) {
return status;
}
// Database does not exist, pick a shard and create a new entry
auto newShardIdStatus = selectShardForNewDatabase(grid.shardRegistry());
if (!newShardIdStatus.isOK()) {
return newShardIdStatus.getStatus();
}
const ShardId& newShardId = newShardIdStatus.getValue();
log() << "Placing [" << dbName << "] on: " << newShardId;
DatabaseType db;
db.setName(dbName);
db.setPrimary(newShardId);
db.setSharded(false);
BatchedCommandResponse response;
status = insert(DatabaseType::ConfigNS, db.toBSON(), &response);
if (status.code() == ErrorCodes::DuplicateKey) {
return Status(ErrorCodes::NamespaceExists, "database " + dbName + " already exists");
}
return status;
}
示例2: updateDatabase
Status CatalogManager::updateDatabase(const std::string& dbName, const DatabaseType& db) {
fassert(28616, db.validate());
BatchedCommandResponse response;
Status status = update(DatabaseType::ConfigNS,
BSON(DatabaseType::name(dbName)),
db.toBSON(),
true, // upsert
false, // multi
&response);
if (!status.isOK()) {
return Status(status.code(),
str::stream() << "database metadata write failed: " << response.toBSON()
<< "; status: " << status.toString());
}
return Status::OK();
}