当前位置: 首页>>代码示例>>C++>>正文


C++ NamespaceString::db方法代码示例

本文整理汇总了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();
}
开发者ID:Ferryworld,项目名称:mongo,代码行数:31,代码来源:view_catalog.cpp

示例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);
}
开发者ID:mikety,项目名称:mongo,代码行数:26,代码来源:view_catalog.cpp

示例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);
}
开发者ID:mikety,项目名称:mongo,代码行数:32,代码来源:view_catalog.cpp

示例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()));
}
开发者ID:visualzhou,项目名称:mongo,代码行数:30,代码来源:view_catalog.cpp

示例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()));
}
开发者ID:visualzhou,项目名称:mongo,代码行数:31,代码来源:view_catalog.cpp

示例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();
}
开发者ID:chickenbug,项目名称:mongo,代码行数:25,代码来源:view_catalog.cpp

示例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();
}
开发者ID:AshishSanju,项目名称:mongo,代码行数:32,代码来源:authorization_session.cpp

示例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(); });
    }
}
开发者ID:visualzhou,项目名称:mongo,代码行数:9,代码来源:durable_view_catalog.cpp

示例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();
    }
开发者ID:7segments,项目名称:mongo-1,代码行数:57,代码来源:rename_collection_common.cpp

示例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());
    }
开发者ID:DINKIN,项目名称:mongo,代码行数:13,代码来源:kv_storage_engine_test.cpp

示例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();
    }
开发者ID:louiswilliams,项目名称:mongo,代码行数:11,代码来源:query_stage_cached_plan.cpp

示例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();
    }
开发者ID:alabid,项目名称:mongo,代码行数:12,代码来源:query_stage_cached_plan.cpp

示例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);
}
开发者ID:RyanBard,项目名称:mongo,代码行数:50,代码来源:capped_utils.cpp

示例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();
        }
    }
开发者ID:Aaron20141021,项目名称:mongo,代码行数:33,代码来源:auth_index_d.cpp

示例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;
}
开发者ID:pgmarchenko,项目名称:mongo,代码行数:29,代码来源:catalog_manager_replica_set.cpp


注:本文中的NamespaceString::db方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。