python类InvalidOperation()的实例源码

message.py 文件源码 项目:mongodb-monitoring 作者: jruaux 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts):
    """Get an **insert** message."""
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
results.py 文件源码 项目:mongodb-monitoring 作者: jruaux 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def acknowledged(self):
        """Is this the result of an acknowledged write operation?

        The :attr:`acknowledged` attribute will be ``False`` when using
        ``WriteConcern(w=0)``, otherwise ``True``.

        .. note::
          If the :attr:`acknowledged` attribute is ``False`` all other
          attibutes of this class will raise
          :class:`~pymongo.errors.InvalidOperation` when accessed. Values for
          other attributes cannot be determined if the write operation was
          unacknowledged.

        .. seealso::
          :class:`~pymongo.write_concern.WriteConcern`
        """
        return self.__acknowledged
cursor.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __check_okay_to_chain(self) -> None:
        """Check if it is okay to chain more options onto this cursor.
        """
        if self.__retrieved or self.__id is not None:
            raise InvalidOperation('cannot set options after executing query')
cursor.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def limit(self, limit) -> 'Cursor':
        """Limits the number of results to be returned by this cursor.

        Raises :exc:`TypeError` if `limit` is not an integer. Raises
        :exc:`~pymongo.errors.InvalidOperation` if this :class:`Cursor`
        has already been used. The last `limit` applied to this cursor
        takes precedence. A limit of ``0`` is equivalent to no limit.

        :Parameters:
          - `limit`: the number of results to return

        .. mongodoc:: limit
        """
        if not isinstance(limit, int):
            raise TypeError('limit must be an integer')

        self.__check_okay_to_chain()

        self.__limit = limit
        return self
cursor.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def max_time_ms(self, max_time_ms: Optional[int]) -> 'Cursor':
        """Specifies a time limit for a query operation. If the specified
        time is exceeded, the operation will be aborted and
        :exc:`~pymongo.errors.ExecutionTimeout` is raised. If `max_time_ms`
        is ``None`` no limit is applied.

        Raises :exc:`TypeError` if `max_time_ms` is not an integer or ``None``.
        Raises :exc:`~pymongo.errors.InvalidOperation` if this :class:`Cursor`
        has already been used.

        :Parameters:
          - `max_time_ms`: the time limit after which the operation is aborted
        """
        if not isinstance(max_time_ms, int) and max_time_ms is not None:
            raise TypeError('max_time_ms must be an integer or None')
        self.__check_okay_to_chain()

        self.__max_time_ms = max_time_ms
        return self
cursor.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def skip(self, skip: int) -> 'Cursor':
        """Skips the first `skip` results of this cursor.

        Raises :exc:`TypeError` if `skip` is not an integer. Raises
        :exc:`ValueError` if `skip` is less than ``0``. Raises
        :exc:`~pymongo.errors.InvalidOperation` if this :class:`Cursor` has
        already been used. The last `skip` applied to this cursor takes
        precedence.

        :Parameters:
          - `skip`: the number of results to skip
        """
        if not isinstance(skip, int):
            raise TypeError('skip must be an integer')
        if skip < 0:
            raise ValueError('skip must be >= 0')
        self.__check_okay_to_chain()

        self.__skip = skip
        return self
cursor.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def collation(self, collation: Collation):
        """Adds a :class:`~pymongo.collation.Collation` to this query.

        This option is only supported on MongoDB 3.4 and above.

        Raises :exc:`TypeError` if `collation` is not an instance of
        :class:`~pymongo.collation.Collation` or a ``dict``. Raises
        :exc:`~pymongo.errors.InvalidOperation` if this :class:`Cursor` has
        already been used. Only the last collation applied to this cursor has
        any effect.

        :Parameters:
          - `collation`: An instance of :class:`~pymongo.collation.Collation`.
        """
        self.__check_okay_to_chain()
        self.__collation = validate_collation_or_none(collation)
        return self
subscriptions.py 文件源码 项目:spymanager 作者: delete 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def add_subscribers(self, subscribers):
        if type(subscribers) != list:
            subscribers = [subscribers]

        for subscriber in subscribers:
            if not self._is_subscriber_exists(subscriber):
                self.bulk.find(
                    {'username': self.username}
                ).update({'$push': {'subscribers': subscriber}})

            else:
                msg = 'Subscriber {} already exists with group {}!'
                print(msg.format(subscriber['spy'], subscriber['group']))
        try:
            self.bulk.execute()
        except InvalidOperation as e:
            print(e)
message.py 文件源码 项目:covar_me_app 作者: CovarMe 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts):
    """Get an **insert** message."""
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
results.py 文件源码 项目:covar_me_app 作者: CovarMe 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def acknowledged(self):
        """Is this the result of an acknowledged write operation?

        The :attr:`acknowledged` attribute will be ``False`` when using
        ``WriteConcern(w=0)``, otherwise ``True``.

        .. note::
          If the :attr:`acknowledged` attribute is ``False`` all other
          attibutes of this class will raise
          :class:`~pymongo.errors.InvalidOperation` when accessed. Values for
          other attributes cannot be determined if the write operation was
          unacknowledged.

        .. seealso::
          :class:`~pymongo.write_concern.WriteConcern`
        """
        return self.__acknowledged
message.py 文件源码 项目:kekescan 作者: xiaoxiaoleo 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts):
    """Get an **insert** message."""
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
results.py 文件源码 项目:kekescan 作者: xiaoxiaoleo 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def acknowledged(self):
        """Is this the result of an acknowledged write operation?

        The :attr:`acknowledged` attribute will be ``False`` when using
        ``WriteConcern(w=0)``, otherwise ``True``.

        .. note::
          If the :attr:`acknowledged` attribute is ``False`` all other
          attibutes of this class will raise
          :class:`~pymongo.errors.InvalidOperation` when accessed. Values for
          other attributes cannot be determined if the write operation was
          unacknowledged.

        .. seealso::
          :class:`~pymongo.write_concern.WriteConcern`
        """
        return self.__acknowledged
message.py 文件源码 项目:flask-zhenai-mongo-echarts 作者: Fretice 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts):
    """Get an **insert** message."""
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
results.py 文件源码 项目:flask-zhenai-mongo-echarts 作者: Fretice 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def acknowledged(self):
        """Is this the result of an acknowledged write operation?

        The :attr:`acknowledged` attribute will be ``False`` when using
        ``WriteConcern(w=0)``, otherwise ``True``.

        .. note::
          If the :attr:`acknowledged` attribute is ``False`` all other
          attibutes of this class will raise
          :class:`~pymongo.errors.InvalidOperation` when accessed. Values for
          other attributes cannot be determined if the write operation was
          unacknowledged.

        .. seealso::
          :class:`~pymongo.write_concern.WriteConcern`
        """
        return self.__acknowledged
message.py 文件源码 项目:Data-visualization 作者: insta-code1 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts):
    """Get an **insert** message."""
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
results.py 文件源码 项目:Data-visualization 作者: insta-code1 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def acknowledged(self):
        """Is this the result of an acknowledged write operation?

        The :attr:`acknowledged` attribute will be ``False`` when using
        ``WriteConcern(w=0)``, otherwise ``True``.

        .. note::
          If the :attr:`acknowledged` attribute is ``False`` all other
          attibutes of this class will raise
          :class:`~pymongo.errors.InvalidOperation` when accessed. Values for
          other attributes cannot be determined if the write operation was
          unacknowledged.

        .. seealso::
          :class:`~pymongo.write_concern.WriteConcern`
        """
        return self.__acknowledged
message.py 文件源码 项目:hudl-bugbounty 作者: lewislabs 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts):
    """Get an **insert** message."""
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
results.py 文件源码 项目:hudl-bugbounty 作者: lewislabs 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def acknowledged(self):
        """Is this the result of an acknowledged write operation?

        The :attr:`acknowledged` attribute will be ``False`` when using
        ``WriteConcern(w=0)``, otherwise ``True``.

        .. note::
          If the :attr:`acknowledged` attribute is ``False`` all other
          attibutes of this class will raise
          :class:`~pymongo.errors.InvalidOperation` when accessed. Values for
          other attributes cannot be determined if the write operation was
          unacknowledged.

        .. seealso::
          :class:`~pymongo.write_concern.WriteConcern`
        """
        return self.__acknowledged
message.py 文件源码 项目:hudl-bugbounty 作者: lewislabs 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts):
    """Get an **insert** message."""
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
results.py 文件源码 项目:hudl-bugbounty 作者: lewislabs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def acknowledged(self):
        """Is this the result of an acknowledged write operation?

        The :attr:`acknowledged` attribute will be ``False`` when using
        ``WriteConcern(w=0)``, otherwise ``True``.

        .. note::
          If the :attr:`acknowledged` attribute is ``False`` all other
          attibutes of this class will raise
          :class:`~pymongo.errors.InvalidOperation` when accessed. Values for
          other attributes cannot be determined if the write operation was
          unacknowledged.

        .. seealso::
          :class:`~pymongo.write_concern.WriteConcern`
        """
        return self.__acknowledged
results.py 文件源码 项目:mongodb-monitoring 作者: jruaux 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _raise_if_unacknowledged(self, property_name):
        """Raise an exception on property access if unacknowledged."""
        if not self.__acknowledged:
            raise InvalidOperation("A value for %s is not available when "
                                   "the write is unacknowledged. Check the "
                                   "acknowledged attribute to avoid this "
                                   "error." % (property_name,))
results.py 文件源码 项目:mongodb-monitoring 作者: jruaux 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __init__(self, bulk_api_result, acknowledged):
        """Create a BulkWriteResult instance.

        :Parameters:
          - `bulk_api_result`: A result dict from the bulk API
          - `acknowledged`: Was this write result acknowledged? If ``False``
            then all properties of this object will raise
            :exc:`~pymongo.errors.InvalidOperation`.
        """
        self.__bulk_api_result = bulk_api_result
        super(BulkWriteResult, self).__init__(acknowledged)
message.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, uuid_subtype):
    """Get an **insert** message.

    .. note:: As of PyMongo 2.6, this function is no longer used. It
       is being kept (with tests) for backwards compatibility with 3rd
       party libraries that may currently be using it, but will likely
       be removed in a future release.

    """
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, uuid_subtype) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
message.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, uuid_subtype):
    """Get an **insert** message.

    .. note:: As of PyMongo 2.6, this function is no longer used. It
       is being kept (with tests) for backwards compatibility with 3rd
       party libraries that may currently be using it, but will likely
       be removed in a future release.

    """
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, uuid_subtype) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
message.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, uuid_subtype):
    """Get an **insert** message.

    .. note:: As of PyMongo 2.6, this function is no longer used. It
       is being kept (with tests) for backwards compatibility with 3rd
       party libraries that may currently be using it, but will likely
       be removed in a future release.

    """
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, uuid_subtype) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
message.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, uuid_subtype):
    """Get an **insert** message.

    .. note:: As of PyMongo 2.6, this function is no longer used. It
       is being kept (with tests) for backwards compatibility with 3rd
       party libraries that may currently be using it, but will likely
       be removed in a future release.

    """
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, uuid_subtype) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
test_bulk.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_empty(self, test_coll):
        bulk = test_coll.initialize_ordered_bulk_op()
        with pytest.raises(InvalidOperation):
            await bulk.execute()
test_bulk.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_multiple_execution(self, test_coll):
        batch = test_coll.initialize_ordered_bulk_op()
        batch.insert({})
        await batch.execute()
        with pytest.raises(InvalidOperation):
            await batch.execute()
test_cursor.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def test_hint(self, test_db):
        with pytest.raises(TypeError):
            test_db.test.find().hint(3.5)
        await test_db.test.drop()

        await test_db.test.insert_many([{'num': i, 'foo': i} for i in range(100)])

        with pytest.raises(OperationFailure):
            await test_db.test.find({'num': 17, 'foo': 17}).hint([('num', ASCENDING)]).explain()

        with pytest.raises(OperationFailure):
            await test_db.test.find({'num': 17, 'foo': 17}).hint([('foo', ASCENDING)]).explain()

        spec = [('num', DESCENDING)]
        await test_db.test.create_index(spec)

        first = await self._next(test_db.test.find())
        assert 0 == first.get('num')
        first = await self._next(test_db.test.find().hint(spec))
        assert 99 == first.get('num')
        with pytest.raises(OperationFailure):
            await test_db.test.find({'num': 17, 'foo': 17}).hint([('foo', ASCENDING)]).explain()

        a = test_db.test.find({'num': 17})
        a.hint(spec)
        async for _ in a:
            break

        with pytest.raises(InvalidOperation):
            a.hint(spec)
test_cursor.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def test_where(self, test_db):
        a = test_db.test.find()

        with pytest.raises(TypeError):
            a.where(5)
        with pytest.raises(TypeError):
            a.where(None)
        with pytest.raises(TypeError):
            a.where({})

        await test_db.test.insert_many([{'x': i} for i in range(10)])

        assert 3 == len(await test_db.test.find().where('this.x < 3').to_list())
        assert 3 == len(await test_db.test.find().where(Code('this.x < 3')).to_list())
        assert 3 == len(await test_db.test.find().where(Code('this.x < i', {'i': 3})).to_list())
        assert 10 == len(await test_db.test.find().to_list())

        assert 3 == await test_db.test.find().where('this.x < 3').count()
        assert 10 == await test_db.test.find().count()
        assert 3 == await test_db.test.find().where(u'this.x < 3').count()
        assert [0, 1, 2] == [a['x'] for a in await test_db.test.find().where('this.x < 3').to_list()]
        assert [] == [a['x'] for a in await test_db.test.find({'x': 5}).where('this.x < 3').to_list()]
        assert [5] == [a['x'] for a in await test_db.test.find({'x': 5}).where('this.x > 3').to_list()]

        cursor = test_db.test.find().where('this.x < 3').where('this.x > 7')
        assert [8, 9] == [a['x'] for a in await cursor.to_list()]

        a = test_db.test.find()
        b = a.where('this.x > 3')
        async for _ in a:
            break
        with pytest.raises(InvalidOperation):
            a.where('this.x < 3')


问题


面经


文章

微信
公众号

扫码关注公众号