當前位置: 首頁>>代碼示例>>Python>>正文


Python ReadPreference.SECONDARY屬性代碼示例

本文整理匯總了Python中pymongo.read_preferences.ReadPreference.SECONDARY屬性的典型用法代碼示例。如果您正苦於以下問題:Python ReadPreference.SECONDARY屬性的具體用法?Python ReadPreference.SECONDARY怎麽用?Python ReadPreference.SECONDARY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在pymongo.read_preferences.ReadPreference的用法示例。


在下文中一共展示了ReadPreference.SECONDARY屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: with_options

# 需要導入模塊: from pymongo.read_preferences import ReadPreference [as 別名]
# 或者: from pymongo.read_preferences.ReadPreference import SECONDARY [as 別名]
def with_options(
            self, codec_options=None, read_preference=None,
            write_concern=None, read_concern=None):
        """Get a clone of this collection changing the specified settings.

          >>> coll1.read_preference
          Primary()
          >>> from pymongo import ReadPreference
          >>> coll2 = coll1.with_options(read_preference=ReadPreference.SECONDARY)
          >>> coll1.read_preference
          Primary()
          >>> coll2.read_preference
          Secondary(tag_sets=None)

        :Parameters:
          - `codec_options` (optional): An instance of
            :class:`~bson.codec_options.CodecOptions`. If ``None`` (the
            default) the :attr:`codec_options` of this :class:`Collection`
            is used.
          - `read_preference` (optional): The read preference to use. If
            ``None`` (the default) the :attr:`read_preference` of this
            :class:`Collection` is used. See :mod:`~pymongo.read_preferences`
            for options.
          - `write_concern` (optional): An instance of
            :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the
            default) the :attr:`write_concern` of this :class:`Collection`
            is used.
          - `read_concern` (optional): An instance of
            :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the
            default) the :attr:`read_concern` of this :class:`Collection`
            is used.
        """
        return Collection(self.__database,
                          self.__name,
                          False,
                          codec_options or self.codec_options,
                          read_preference or self.read_preference,
                          write_concern or self.write_concern,
                          read_concern or self.read_concern) 
開發者ID:jruaux,項目名稱:mongodb-monitoring,代碼行數:41,代碼來源:collection.py

示例2: matches_mode

# 需要導入模塊: from pymongo.read_preferences import ReadPreference [as 別名]
# 或者: from pymongo.read_preferences.ReadPreference import SECONDARY [as 別名]
def matches_mode(self, mode):
        assert not self.is_mongos, \
            "Tried to match read preference mode on a mongos Member"

        if mode == ReadPreference.PRIMARY and not self.is_primary:
            return False

        if mode == ReadPreference.SECONDARY and not self.is_secondary:
            return False

        # If we're not primary or secondary, then we're in a state like
        # RECOVERING and we don't match any mode
        return self.is_primary or self.is_secondary 
開發者ID:DirceuSilvaLabs,項目名稱:noc-orchestrator,代碼行數:15,代碼來源:member.py

示例3: test_get_collection

# 需要導入模塊: from pymongo.read_preferences import ReadPreference [as 別名]
# 或者: from pymongo.read_preferences.ReadPreference import SECONDARY [as 別名]
def test_get_collection(self, test_db):
        codec_options = CodecOptions(tz_aware=True)
        write_concern = WriteConcern(w=2, j=True)
        read_concern = ReadConcern('majority')
        coll = test_db.get_collection(
            'foo', codec_options, ReadPreference.SECONDARY, write_concern,
            read_concern)
        assert 'foo' == coll.name
        assert codec_options == coll.codec_options
        assert ReadPreference.SECONDARY == coll.read_preference
        assert write_concern == coll.write_concern
        assert read_concern == coll.read_concern 
開發者ID:ZeoAlliance,項目名稱:aiomongo,代碼行數:14,代碼來源:test_database.py

示例4: with_options

# 需要導入模塊: from pymongo.read_preferences import ReadPreference [as 別名]
# 或者: from pymongo.read_preferences.ReadPreference import SECONDARY [as 別名]
def with_options(self, codec_options: Optional[CodecOptions] = None,
                     read_preference: Optional[Union[_ALL_READ_PREFERENCES]] = None,
                     write_concern: Optional[WriteConcern] = None,
                     read_concern: Optional[ReadConcern] = None) -> 'Collection':
        """Get a clone of this collection changing the specified settings.

          >>> coll1.read_preference
          Primary()
          >>> from pymongo import ReadPreference
          >>> coll2 = coll1.with_options(read_preference=ReadPreference.SECONDARY)
          >>> coll1.read_preference
          Primary()
          >>> coll2.read_preference
          Secondary(tag_sets=None)

        :Parameters:
          - `codec_options` (optional): An instance of
            :class:`~bson.codec_options.CodecOptions`. If ``None`` (the
            default) the :attr:`codec_options` of this :class:`Collection`
            is used.
          - `read_preference` (optional): The read preference to use. If
            ``None`` (the default) the :attr:`read_preference` of this
            :class:`Collection` is used. See :mod:`~pymongo.read_preferences`
            for options.
          - `write_concern` (optional): An instance of
            :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the
            default) the :attr:`write_concern` of this :class:`Collection`
            is used.
          - `read_concern` (optional): An instance of
            :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the
            default) the :attr:`read_concern` of this :class:`Collection`
            is used.
        """
        return Collection(self.database,
                          self.name,
                          read_preference or self.read_preference,
                          read_concern or self.read_concern,
                          codec_options or self.codec_options,
                          write_concern or self.write_concern) 
開發者ID:ZeoAlliance,項目名稱:aiomongo,代碼行數:41,代碼來源:collection.py

示例5: get_collection

# 需要導入模塊: from pymongo.read_preferences import ReadPreference [as 別名]
# 或者: from pymongo.read_preferences.ReadPreference import SECONDARY [as 別名]
def get_collection(self, name, codec_options=None, read_preference=None,
                       write_concern=None, read_concern=None):
        """Get a :class:`~pymongo.collection.Collection` with the given name
        and options.

        Useful for creating a :class:`~pymongo.collection.Collection` with
        different codec options, read preference, and/or write concern from
        this :class:`Database`.

          >>> db.read_preference
          Primary()
          >>> coll1 = db.test
          >>> coll1.read_preference
          Primary()
          >>> from pymongo import ReadPreference
          >>> coll2 = db.get_collection(
          ...     'test', read_preference=ReadPreference.SECONDARY)
          >>> coll2.read_preference
          Secondary(tag_sets=None)

        :Parameters:
          - `name`: The name of the collection - a string.
          - `codec_options` (optional): An instance of
            :class:`~bson.codec_options.CodecOptions`. If ``None`` (the
            default) the :attr:`codec_options` of this :class:`Database` is
            used.
          - `read_preference` (optional): The read preference to use. If
            ``None`` (the default) the :attr:`read_preference` of this
            :class:`Database` is used. See :mod:`~pymongo.read_preferences`
            for options.
          - `write_concern` (optional): An instance of
            :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the
            default) the :attr:`write_concern` of this :class:`Database` is
            used.
          - `read_concern` (optional): An instance of
            :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the
            default) the :attr:`read_concern` of this :class:`Database` is
            used.
        """
        return Collection(
            self, name, False, codec_options, read_preference,
            write_concern, read_concern) 
開發者ID:jruaux,項目名稱:mongodb-monitoring,代碼行數:44,代碼來源:database.py

示例6: get_database

# 需要導入模塊: from pymongo.read_preferences import ReadPreference [as 別名]
# 或者: from pymongo.read_preferences.ReadPreference import SECONDARY [as 別名]
def get_database(self, name, codec_options=None, read_preference=None,
                     write_concern=None, read_concern=None):
        """Get a :class:`~pymongo.database.Database` with the given name and
        options.

        Useful for creating a :class:`~pymongo.database.Database` with
        different codec options, read preference, and/or write concern from
        this :class:`MongoClient`.

          >>> client.read_preference
          Primary()
          >>> db1 = client.test
          >>> db1.read_preference
          Primary()
          >>> from pymongo import ReadPreference
          >>> db2 = client.get_database(
          ...     'test', read_preference=ReadPreference.SECONDARY)
          >>> db2.read_preference
          Secondary(tag_sets=None)

        :Parameters:
          - `name`: The name of the database - a string.
          - `codec_options` (optional): An instance of
            :class:`~bson.codec_options.CodecOptions`. If ``None`` (the
            default) the :attr:`codec_options` of this :class:`MongoClient` is
            used.
          - `read_preference` (optional): The read preference to use. If
            ``None`` (the default) the :attr:`read_preference` of this
            :class:`MongoClient` is used. See :mod:`~pymongo.read_preferences`
            for options.
          - `write_concern` (optional): An instance of
            :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the
            default) the :attr:`write_concern` of this :class:`MongoClient` is
            used.
          - `read_concern` (optional): An instance of
            :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the
            default) the :attr:`read_concern` of this :class:`MongoClient` is
            used.
        """
        return database.Database(
            self, name, codec_options, read_preference,
            write_concern, read_concern) 
開發者ID:jruaux,項目名稱:mongodb-monitoring,代碼行數:44,代碼來源:mongo_client.py

示例7: __init__

# 需要導入模塊: from pymongo.read_preferences import ReadPreference [as 別名]
# 或者: from pymongo.read_preferences.ReadPreference import SECONDARY [as 別名]
def __init__(self, host, connection_pool, ismaster_response, ping_time):
        self.host = host
        self.pool = connection_pool
        self.ismaster_response = ismaster_response
        self.ping_time = ping_time
        self.is_mongos = (ismaster_response.get('msg') == 'isdbgrid')

        if ismaster_response['ismaster']:
            self.state = PRIMARY
        elif ismaster_response.get('secondary'):
            self.state = SECONDARY
        elif ismaster_response.get('arbiterOnly'):
            self.state = ARBITER
        else:
            self.state = OTHER

        self.set_name = ismaster_response.get('setName')
        self.tags = ismaster_response.get('tags', {})
        self.max_bson_size = ismaster_response.get(
            'maxBsonObjectSize', common.MAX_BSON_SIZE)
        self.max_message_size = ismaster_response.get(
            'maxMessageSizeBytes', 2 * self.max_bson_size)
        self.min_wire_version = ismaster_response.get(
            'minWireVersion', common.MIN_WIRE_VERSION)
        self.max_wire_version = ismaster_response.get(
            'maxWireVersion', common.MAX_WIRE_VERSION)
        self.max_write_batch_size = ismaster_response.get(
            'maxWriteBatchSize', common.MAX_WRITE_BATCH_SIZE)

        # self.min/max_wire_version is the server's wire protocol.
        # MIN/MAX_SUPPORTED_WIRE_VERSION is what PyMongo supports.
        if (
            # Server too new.
            common.MAX_SUPPORTED_WIRE_VERSION < self.min_wire_version
            # Server too old.
            or common.MIN_SUPPORTED_WIRE_VERSION > self.max_wire_version
        ):
            raise ConfigurationError(
                "Server at %s:%d uses wire protocol versions %d through %d, "
                "but PyMongo only supports %d through %d"
                % (self.host[0], self.host[1],
                   self.min_wire_version, self.max_wire_version,
                   common.MIN_SUPPORTED_WIRE_VERSION,
                   common.MAX_SUPPORTED_WIRE_VERSION)) 
開發者ID:DirceuSilvaLabs,項目名稱:noc-orchestrator,代碼行數:46,代碼來源:member.py

示例8: get_collection

# 需要導入模塊: from pymongo.read_preferences import ReadPreference [as 別名]
# 或者: from pymongo.read_preferences.ReadPreference import SECONDARY [as 別名]
def get_collection(self, name: str, codec_options: Optional[CodecOptions] = None,
                       read_preference: Optional[Union[_ALL_READ_PREFERENCES]] = None,
                       write_concern: Optional[WriteConcern] = None,
                       read_concern: Optional[ReadConcern] = None):
        """Get a :class:`~aiomongo.collection.Collection` with the given name
        and options.

        Useful for creating a :class:`~aiomongo.collection.Collection` with
        different codec options, read preference, and/or write concern from
        this :class:`Database`.

          >>> db.read_preference
          Primary()
          >>> coll1 = db.test
          >>> coll1.read_preference
          Primary()
          >>> from pymongo import ReadPreference
          >>> coll2 = db.get_collection(
          ...     'test', read_preference=ReadPreference.SECONDARY)
          >>> coll2.read_preference
          Secondary(tag_sets=None)

        :Parameters:
          - `name`: The name of the collection - a string.
          - `codec_options` (optional): An instance of
            :class:`~bson.codec_options.CodecOptions`. If ``None`` (the
            default) the :attr:`codec_options` of this :class:`Database` is
            used.
          - `read_preference` (optional): The read preference to use. If
            ``None`` (the default) the :attr:`read_preference` of this
            :class:`Database` is used. See :mod:`~pymongo.read_preferences`
            for options.
          - `write_concern` (optional): An instance of
            :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the
            default) the :attr:`write_concern` of this :class:`Database` is
            used.
          - `read_concern` (optional): An instance of
            :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the
            default) the :attr:`read_concern` of this :class:`Database` is
            used.
        """
        return Collection(
            self, name, read_preference, read_concern,
            codec_options, write_concern) 
開發者ID:ZeoAlliance,項目名稱:aiomongo,代碼行數:46,代碼來源:database.py


注:本文中的pymongo.read_preferences.ReadPreference.SECONDARY屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。