本文整理汇总了C++中NamespaceString::db方法的典型用法代码示例。如果您正苦于以下问题:C++ NamespaceString::db方法的具体用法?C++ NamespaceString::db怎么用?C++ NamespaceString::db使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceString
的用法示例。
在下文中一共展示了NamespaceString::db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createView
Status ViewCatalog::createView(OperationContext* txn,
const NamespaceString& viewName,
const NamespaceString& viewOn,
const BSONObj& pipeline) {
if (!enableViews)
return Status(ErrorCodes::CommandNotSupported, "View support not enabled");
if (viewName.db() != viewOn.db())
return Status(ErrorCodes::BadValue,
"View must be created on a view or collection in the same database");
if (lookup(StringData(viewName.ns())))
return Status(ErrorCodes::NamespaceExists, "Namespace already exists");
if (!NamespaceString::validCollectionName(viewOn.coll()))
return Status(ErrorCodes::InvalidNamespace,
str::stream() << "invalid name for 'viewOn': " << viewOn.coll());
// TODO(SERVER-24768): Need to ensure view is correct and doesn't introduce a cycle.
BSONObj viewDef =
BSON("_id" << viewName.ns() << "viewOn" << viewOn.coll() << "pipeline" << pipeline);
_durable->insert(txn, viewDef);
BSONObj ownedPipeline = pipeline.getOwned();
_viewMap[viewName.ns()] = std::make_shared<ViewDefinition>(
viewName.db(), viewName.coll(), viewOn.coll(), ownedPipeline);
txn->recoveryUnit()->onRollback([this, viewName]() { this->_viewMap.erase(viewName.ns()); });
return Status::OK();
}
示例2: createView
Status ViewCatalog::createView(OperationContext* txn,
const NamespaceString& viewName,
const NamespaceString& viewOn,
const BSONArray& pipeline) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
if (serverGlobalParams.featureCompatibilityVersion.load() ==
ServerGlobalParams::FeatureCompatibilityVersion_32) {
return Status(ErrorCodes::CommandNotSupported,
"Cannot create view when the featureCompatibilityVersion is 3.2. See "
"http://dochub.mongodb.org/core/3.4-feature-compatibility.");
}
if (viewName.db() != viewOn.db())
return Status(ErrorCodes::BadValue,
"View must be created on a view or collection in the same database");
if (_lookup_inlock(txn, StringData(viewName.ns())))
return Status(ErrorCodes::NamespaceExists, "Namespace already exists");
if (!NamespaceString::validCollectionName(viewOn.coll()))
return Status(ErrorCodes::InvalidNamespace,
str::stream() << "invalid name for 'viewOn': " << viewOn.coll());
return _createOrUpdateView_inlock(txn, viewName, viewOn, pipeline);
}
示例3: modifyView
Status ViewCatalog::modifyView(OperationContext* txn,
const NamespaceString& viewName,
const NamespaceString& viewOn,
const BSONArray& pipeline) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
if (serverGlobalParams.featureCompatibilityVersion.load() ==
ServerGlobalParams::FeatureCompatibilityVersion_32) {
return Status(ErrorCodes::CommandNotSupported,
"Cannot modify view when the featureCompatibilityVersion is 3.2. See "
"http://dochub.mongodb.org/core/3.4-feature-compatibility.");
}
if (viewName.db() != viewOn.db())
return Status(ErrorCodes::BadValue,
"View must be created on a view or collection in the same database");
auto viewPtr = _lookup_inlock(txn, viewName.ns());
if (!viewPtr)
return Status(ErrorCodes::NamespaceNotFound,
str::stream() << "cannot modify missing view " << viewName.ns());
if (!NamespaceString::validCollectionName(viewOn.coll()))
return Status(ErrorCodes::InvalidNamespace,
str::stream() << "invalid name for 'viewOn': " << viewOn.coll());
ViewDefinition savedDefinition = *viewPtr;
txn->recoveryUnit()->onRollback([this, txn, viewName, savedDefinition]() {
this->_viewMap[viewName.ns()] = std::make_shared<ViewDefinition>(savedDefinition);
});
return _createOrUpdateView_inlock(txn, viewName, viewOn, pipeline);
}
示例4: createView
Status ViewCatalog::createView(OperationContext* opCtx,
const NamespaceString& viewName,
const NamespaceString& viewOn,
const BSONArray& pipeline,
const BSONObj& collation) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
if (viewName.db() != viewOn.db())
return Status(ErrorCodes::BadValue,
"View must be created on a view or collection in the same database");
if (_lookup(lk, opCtx, StringData(viewName.ns())))
return Status(ErrorCodes::NamespaceExists, "Namespace already exists");
if (!NamespaceString::validCollectionName(viewOn.coll()))
return Status(ErrorCodes::InvalidNamespace,
str::stream() << "invalid name for 'viewOn': " << viewOn.coll());
if (viewName.isSystem())
return Status(
ErrorCodes::InvalidNamespace,
"View name cannot start with 'system.', which is reserved for system namespaces");
auto collator = parseCollator(opCtx, collation);
if (!collator.isOK())
return collator.getStatus();
return _createOrUpdateView(
lk, opCtx, viewName, viewOn, pipeline, std::move(collator.getValue()));
}
示例5: modifyView
Status ViewCatalog::modifyView(OperationContext* opCtx,
const NamespaceString& viewName,
const NamespaceString& viewOn,
const BSONArray& pipeline) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
if (viewName.db() != viewOn.db())
return Status(ErrorCodes::BadValue,
"View must be created on a view or collection in the same database");
auto viewPtr = _lookup(lk, opCtx, viewName.ns());
if (!viewPtr)
return Status(ErrorCodes::NamespaceNotFound,
str::stream() << "cannot modify missing view " << viewName.ns());
if (!NamespaceString::validCollectionName(viewOn.coll()))
return Status(ErrorCodes::InvalidNamespace,
str::stream() << "invalid name for 'viewOn': " << viewOn.coll());
ViewDefinition savedDefinition = *viewPtr;
opCtx->recoveryUnit()->onRollback([this, viewName, savedDefinition]() {
this->_viewMap[viewName.ns()] = std::make_shared<ViewDefinition>(savedDefinition);
});
return _createOrUpdateView(lk,
opCtx,
viewName,
viewOn,
pipeline,
CollatorInterface::cloneCollator(savedDefinition.defaultCollator()));
}
示例6: createView
Status ViewCatalog::createView(OperationContext* txn,
const NamespaceString& viewName,
const NamespaceString& viewOn,
const BSONArray& pipeline) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
if (!enableViews)
return Status(ErrorCodes::CommandNotSupported, "View support not enabled");
if (viewName.db() != viewOn.db())
return Status(ErrorCodes::BadValue,
"View must be created on a view or collection in the same database");
if (_lookup_inlock(txn, StringData(viewName.ns())))
return Status(ErrorCodes::NamespaceExists, "Namespace already exists");
if (!NamespaceString::validCollectionName(viewOn.coll()))
return Status(ErrorCodes::InvalidNamespace,
str::stream() << "invalid name for 'viewOn': " << viewOn.coll());
// TODO(SERVER-24768): Need to ensure view is correct and doesn't introduce a cycle.
_createOrUpdateView_inlock(txn, viewName, viewOn, pipeline);
return Status::OK();
}
示例7: checkAuthForKillCursors
Status AuthorizationSession::checkAuthForKillCursors(const NamespaceString& ns,
long long cursorID) {
// See implementation comments in checkAuthForGetMore(). This method looks very similar.
// SERVER-20364 Check for find or killCursor privileges until we have a way of associating
// a cursor with an owner.
if (ns.isListCollectionsCursorNS()) {
if (!(isAuthorizedForActionsOnResource(ResourcePattern::forDatabaseName(ns.db()),
ActionType::killCursors) ||
isAuthorizedForActionsOnResource(ResourcePattern::forDatabaseName(ns.db()),
ActionType::listCollections))) {
return Status(ErrorCodes::Unauthorized,
str::stream() << "not authorized to kill listCollections cursor on "
<< ns.ns());
}
} else if (ns.isListIndexesCursorNS()) {
NamespaceString targetNS = ns.getTargetNSForListIndexes();
if (!(isAuthorizedForActionsOnNamespace(targetNS, ActionType::killCursors) ||
isAuthorizedForActionsOnNamespace(targetNS, ActionType::listIndexes))) {
return Status(ErrorCodes::Unauthorized,
str::stream() << "not authorized to kill listIndexes cursor on "
<< ns.ns());
}
} else {
if (!(isAuthorizedForActionsOnNamespace(ns, ActionType::killCursors) ||
isAuthorizedForActionsOnNamespace(ns, ActionType::find))) {
return Status(ErrorCodes::Unauthorized,
str::stream() << "not authorized to kill cursor on " << ns.ns());
}
}
return Status::OK();
}
示例8: onExternalChange
void DurableViewCatalog::onExternalChange(OperationContext* opCtx, const NamespaceString& name) {
dassert(opCtx->lockState()->isDbLockedForMode(name.db(), MODE_IX));
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, name.db());
if (db) {
opCtx->recoveryUnit()->onCommit(
[db](boost::optional<Timestamp>) { ViewCatalog::get(db)->invalidate(); });
}
}
示例9: checkAuthForRenameCollectionCommand
Status checkAuthForRenameCollectionCommand(ClientBasic* client,
const std::string& dbname,
const BSONObj& cmdObj) {
NamespaceString sourceNS = NamespaceString(cmdObj.getStringField("renameCollection"));
NamespaceString targetNS = NamespaceString(cmdObj.getStringField("to"));
bool dropTarget = cmdObj["dropTarget"].trueValue();
if (sourceNS.db() == targetNS.db() && !sourceNS.isSystem() && !targetNS.isSystem()) {
// If renaming within the same database, then if you have renameCollectionSameDB and
// either can read both of source and dest collections or *can't* read either of source
// or dest collection, then you get can do the rename, even without insert on the
// destination collection.
bool canRename = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forDatabaseName(sourceNS.db()),
ActionType::renameCollectionSameDB);
bool canDropTargetIfNeeded = true;
if (dropTarget) {
canDropTargetIfNeeded =
AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(targetNS),
ActionType::dropCollection);
}
bool canReadSrc = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(sourceNS), ActionType::find);
bool canReadDest = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(targetNS), ActionType::find);
if (canRename && canDropTargetIfNeeded && (canReadSrc || !canReadDest)) {
return Status::OK();
}
}
// Check privileges on source collection
ActionSet actions;
actions.addAction(ActionType::find);
actions.addAction(ActionType::dropCollection);
if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(sourceNS), actions)) {
return Status(ErrorCodes::Unauthorized, "Unauthorized");
}
// Check privileges on dest collection
actions.removeAllActions();
actions.addAction(ActionType::insert);
actions.addAction(ActionType::createIndex);
if (dropTarget) {
actions.addAction(ActionType::dropCollection);
}
if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(targetNS), actions)) {
return Status(ErrorCodes::Unauthorized, "Unauthorized");
}
return Status::OK();
}
示例10: db
/**
* Create a collection in the catalog and in the KVEngine. Return the storage engine's `ident`.
*/
StatusWith<std::string> createCollection(OperationContext* opCtx, NamespaceString ns) {
AutoGetDb db(opCtx, ns.db(), LockMode::MODE_X);
DatabaseCatalogEntry* dbce = _storageEngine->getDatabaseCatalogEntry(opCtx, ns.db());
auto ret = dbce->createCollection(opCtx, ns.ns(), CollectionOptions(), false);
if (!ret.isOK()) {
return ret;
}
return _storageEngine->getCatalog()->getCollectionIdent(ns.ns());
}
示例11: dropCollection
void dropCollection() {
Lock::DBLock dbLock(&_opCtx, nss.db(), MODE_X);
Database* database = DatabaseHolder::getDatabaseHolder().get(&_opCtx, nss.db());
if (!database) {
return;
}
WriteUnitOfWork wuow(&_opCtx);
database->dropCollection(&_opCtx, nss.ns()).transitional_ignore();
wuow.commit();
}
示例12: dropCollection
void dropCollection() {
ScopedTransaction transaction(&_txn, MODE_X);
Lock::DBLock dbLock(_txn.lockState(), nss.db(), MODE_X);
Database* database = dbHolder().get(&_txn, nss.db());
if (!database) {
return;
}
WriteUnitOfWork wuow(&_txn);
database->dropCollection(&_txn, nss.ns());
wuow.commit();
}
示例13: convertToCapped
mongo::Status mongo::convertToCapped(OperationContext* opCtx,
const NamespaceString& collectionName,
long long size) {
StringData dbname = collectionName.db();
StringData shortSource = collectionName.coll();
AutoGetDb autoDb(opCtx, collectionName.db(), MODE_X);
bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() &&
!repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, collectionName);
if (userInitiatedWritesAndNotPrimary) {
return Status(ErrorCodes::NotMaster,
str::stream() << "Not primary while converting " << collectionName.ns()
<< " to a capped collection");
}
Database* const db = autoDb.getDb();
if (!db) {
return Status(ErrorCodes::NamespaceNotFound,
str::stream() << "database " << dbname << " not found");
}
BackgroundOperation::assertNoBgOpInProgForDb(dbname);
// Generate a temporary collection name that will not collide with any existing collections.
auto tmpNameResult =
db->makeUniqueCollectionNamespace(opCtx, "tmp%%%%%.convertToCapped." + shortSource);
if (!tmpNameResult.isOK()) {
return tmpNameResult.getStatus().withContext(
str::stream() << "Cannot generate temporary collection namespace to convert "
<< collectionName.ns()
<< " to a capped collection");
}
const auto& longTmpName = tmpNameResult.getValue();
const auto shortTmpName = longTmpName.coll().toString();
{
Status status =
cloneCollectionAsCapped(opCtx, db, shortSource.toString(), shortTmpName, size, true);
if (!status.isOK())
return status;
}
RenameCollectionOptions options;
options.dropTarget = true;
options.stayTemp = false;
return renameCollection(opCtx, longTmpName, collectionName, options);
}
示例14: configureSystemIndexes
void configureSystemIndexes(OperationContext* txn) {
int authzVersion;
Status status = getGlobalAuthorizationManager()->getAuthorizationVersion(
txn, &authzVersion);
if (!status.isOK()) {
return;
}
if (authzVersion >= AuthorizationManager::schemaVersion26Final) {
const NamespaceString systemUsers("admin", "system.users");
// Make sure the old unique index from v2.4 on system.users doesn't exist.
AutoGetDb autoDb(txn, systemUsers.db(), MODE_X);
if (!autoDb.getDb()) {
return;
}
Collection* collection = autoDb.getDb()->getCollection(txn,
NamespaceString(systemUsers));
if (!collection) {
return;
}
IndexCatalog* indexCatalog = collection->getIndexCatalog();
IndexDescriptor* oldIndex = NULL;
WriteUnitOfWork wunit(txn);
while ((oldIndex = indexCatalog->findIndexByKeyPattern(txn, v1SystemUsersKeyPattern))) {
indexCatalog->dropIndex(txn, oldIndex);
}
wunit.commit();
}
}
示例15: bsonExtractIntegerField
StatusWith<long long> CatalogManagerReplicaSet::_runCountCommandOnConfig(const HostAndPort& target,
const NamespaceString& ns,
BSONObj query) {
BSONObjBuilder countBuilder;
countBuilder.append("count", ns.coll());
countBuilder.append("query", query);
_appendReadConcern(&countBuilder);
auto responseStatus =
grid.shardRegistry()->runCommandOnConfig(target, ns.db().toString(), countBuilder.done());
if (!responseStatus.isOK()) {
return responseStatus.getStatus();
}
auto responseObj = responseStatus.getValue();
Status status = Command::getStatusFromCommandResult(responseObj);
if (!status.isOK()) {
return status;
}
long long result;
status = bsonExtractIntegerField(responseObj, "n", &result);
if (!status.isOK()) {
return status;
}
return result;
}