1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
=================
Exception Classes
=================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
MongoDB\\Exception\\BadMethodCallException
------------------------------------------
.. phpclass:: MongoDB\\Exception\\BadMethodCallException
This exception is thrown when an unsupported method is invoked on an object.
For example, using an unacknowledged write concern with
:phpmethod:`MongoDB\\Collection::insertMany()` will return a
:phpclass:`MongoDB\\InsertManyResult` object. It is a logical error to call
:phpmethod:`MongoDB\\InsertManyResult::getInsertedCount()`, since the number
of inserted documents can only be determined from the response of an
acknowledged write operation.
This class extends PHP's :php:`BadMethodCallException
<badmethodcallexception>` class and implements the library's
:phpclass:`Exception <MongoDB\\Exception\\Exception>` interface.
----
MongoDB\\Exception\\InvalidArgumentException
--------------------------------------------
.. phpclass:: MongoDB\\Exception\\InvalidArgumentException
Thrown for errors related to the parsing of parameters or options within the
library.
This class extends the driver's :php:`InvalidArgumentException
<mongodb-driver-exception-invalidargumentexception>` class and implements the
library's :phpclass:`Exception <MongoDB\\Exception\\Exception>` interface.
----
MongoDB\\Exception\\UnexpectedValueException
--------------------------------------------
.. phpclass:: MongoDB\\Exception\\UnexpectedValueException
This exception is thrown when a command response from the server is
malformed or not what the library expected. This exception means that an
assertion in some operation, which abstracts a database command, has failed.
It may indicate a corrupted BSON response or bug in the server, driver, or
library.
This class extends the driver's :php:`UnexpectedValueException
<mongodb-driver-exception-unexpectedvalueexception>` class and implements the
library's :phpclass:`Exception <MongoDB\\Exception\\Exception>` interface.
----
MongoDB\\Exception\\UnsupportedException
----------------------------------------
.. phpclass:: MongoDB\\Exception\\UnsupportedException
This exception is thrown if an option is used and not supported by the
selected server. It is used sparingly in cases where silently ignoring the
unsupported option might otherwise lead to unexpected behavior.
For example, the ``collation`` option for
:phpmethod:`MongoDB\\Collection::deleteOne()` is only supported by
MongoDB 3.4+. Since collation determines how a document is matched, silently
ignoring the option for an older server version could result in an
unintended document being deleted.
This class extends the library's :phpclass:`RuntimeException
<MongoDB\\Exception\\RuntimeException>` class.
.. note::
Unlike :phpclass:`InvalidArgumentException
<MongoDB\\Exception\\InvalidArgumentException>`, which may be thrown when
an operation's parameters and options are parsed during construction, the
selected server is not known until an operation is executed.
----
MongoDB\\GridFS\\Exception\\CorruptFileException
------------------------------------------------
.. phpclass:: MongoDB\\GridFS\\Exception\\CorruptFileException
This exception is thrown if a GridFS file's metadata or chunk documents
contain unexpected or invalid data.
When selecting a GridFS file, this may be thrown if a metadata field has an
incorrect type or its value is out of range (e.g. negative ``length``). When
reading a GridFS file, this may be thrown if a chunk's index is out of
sequence or its binary data's length out of range.
This class extends the library's :phpclass:`RuntimeException
<MongoDB\\Exception\\RuntimeException>` class.
----
MongoDB\\GridFS\\Exception\\FileNotFoundException
-------------------------------------------------
.. phpclass:: MongoDB\\GridFS\\Exception\\FileNotFoundException
This exception is thrown if no GridFS file was found for the selection
criteria (e.g. ``id``, ``filename``).
This class extends the library's :phpclass:`RuntimeException
<MongoDB\\Exception\\RuntimeException>` class.
----
MongoDB\\Exception\\Exception
-----------------------------
.. phpclass:: MongoDB\\Exception\\Exception
This interface extends the driver's :php:`Exception
<mongodb-driver-exception-exception>` interface and is implemented by all
exception classes within the library.
----
MongoDB\\Exception\\RuntimeException
------------------------------------
.. phpclass:: MongoDB\\Exception\\RuntimeException
This class extends the driver's :php:`RuntimeException
<mongodb-driver-exception-runtimeexception>` class, which in turn extends
PHP's :php:`RuntimeException <runtimeexception>` class.