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


Python Topology.get_primary方法代码示例

本文整理汇总了Python中pymongo.topology.Topology.get_primary方法的典型用法代码示例。如果您正苦于以下问题:Python Topology.get_primary方法的具体用法?Python Topology.get_primary怎么用?Python Topology.get_primary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo.topology.Topology的用法示例。


在下文中一共展示了Topology.get_primary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MongoClient

# 需要导入模块: from pymongo.topology import Topology [as 别名]
# 或者: from pymongo.topology.Topology import get_primary [as 别名]

#.........这里部分代码省略.........
        except ConnectionFailure:
            return default

    @property
    def address(self):
        """(host, port) of the current standalone, primary, or mongos, or None.

        Accessing :attr:`address` raises :exc:`~.errors.InvalidOperation` if
        the client is load-balancing among mongoses, since there is no single
        address. Use :attr:`nodes` instead.

        .. versionadded:: 3.0
        """
        try:
            return self._topology.get_direct_or_primary()
        except InvalidOperation:
            # Only one case where Topology throws InvalidOperation.
            raise InvalidOperation(
                'Cannot use "address" property when load balancing among'
                ' mongoses, use "nodes" instead.')

    @property
    def primary(self):
        """The (host, port) of the current primary of the replica set.

        Returns ``None`` if this client is not connected to a replica set,
        there is no primary, or this client was created without the
        `replicaSet` option.

        .. versionadded:: 3.0
           MongoClient gained this property in version 3.0 when
           MongoReplicaSetClient's functionality was merged in.
        """
        return self._topology.get_primary()

    @property
    def secondaries(self):
        """The secondary members known to this client.

        A sequence of (host, port) pairs. Empty if this client is not
        connected to a replica set, there are no visible secondaries, or this
        client was created without the `replicaSet` option.

        .. versionadded:: 3.0
           MongoClient gained this property in version 3.0 when
           MongoReplicaSetClient's functionality was merged in.
        """
        return self._topology.get_secondaries()

    @property
    def arbiters(self):
        """Arbiters in the replica set.

        A sequence of (host, port) pairs. Empty if this client is not
        connected to a replica set, there are no arbiters, or this client was
        created without the `replicaSet` option.
        """
        return self._topology.get_arbiters()

    @property
    def is_primary(self):
        """If this client if connected to a server that can accept writes.

        True if the current server is a standalone, mongos, or the primary of
        a replica set.
        """
开发者ID:ToontownBattlefront,项目名称:Toontown-Battlefront,代码行数:70,代码来源:mongo_client.py


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