本文整理汇总了Python中pymongo.errors.InvalidOperation方法的典型用法代码示例。如果您正苦于以下问题:Python errors.InvalidOperation方法的具体用法?Python errors.InvalidOperation怎么用?Python errors.InvalidOperation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.errors
的用法示例。
在下文中一共展示了errors.InvalidOperation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: acknowledged
# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
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
示例2: insert
# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
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)
示例3: test_cursor_first
# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
def test_cursor_first(collection):
collection.insert_many([{"bar": "baz"},
{"bar": "qux"}])
cursor = Cursor(collection)
result = cursor.first()
assert isinstance(result, dict)
assert result["bar"] == "baz"
with pytest.raises(InvalidOperation):
cursor.first()
class Foo(Thingy):
_collection = collection
cursor = Cursor(collection, thingy_cls=Foo)
result = cursor.first()
assert isinstance(result, Foo)
assert result.bar == "baz"
with pytest.raises(InvalidOperation):
cursor.first()
示例4: insert
# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
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(list(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)
示例5: _raise_if_unacknowledged
# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
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,))
示例6: __init__
# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
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)