1MONGOC_ERRORS(3) libmongoc MONGOC_ERRORS(3)
2
3
4
6 mongoc_errors - Error Reporting « index
7
9 Many C Driver functions report errors by returning false or -1 and
10 filling out a bson_error_t structure with an error domain, error code,
11 and message. Use domain to determine which subsystem generated the er‐
12 ror, and code for the specific error. message is a human-readable error
13 description.
14
15 See also: Handling Errors in libbson.
16
17 ┌────────────────────┬──────────────────────────────────┬────────────────────────┐
18 │Domain │ Code │ Description │
19 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
20 │MONGOC_ERROR_CLIENT │ MONGOC_ER‐ │ You tried to send a │
21 │ │ ROR_CLIENT_TOO_BIG │ message larger than │
22 │ │ │ the server's max │
23 │ │ │ message size. │
24 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
25 │ │ MONGOC_ER‐ │ Wrong credentials, │
26 │ │ ROR_CLIENT_AUTHEN‐ │ or failure sending │
27 │ │ TICATE │ or receiving au‐ │
28 │ │ │ thentication mes‐ │
29 │ │ │ sages. │
30 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
31 │ │ MONGOC_ER‐ │ You tried an TLS │
32 │ │ ROR_CLIENT_NO_AC‐ │ connection but the │
33 │ │ CEPTABLE_PEER │ driver was not │
34 │ │ │ built with TLS. │
35 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
36 │ │ MONGOC_ER‐ │ You began iterating │
37 │ │ ROR_CLIENT_IN_EX‐ │ an exhaust cursor, │
38 │ │ HAUST │ then tried to begin │
39 │ │ │ another operation │
40 │ │ │ with the same mon‐ │
41 │ │ │ goc_client_t. │
42 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
43 │ │ MONGOC_ER‐ │ Failure related to │
44 │ │ ROR_CLIENT_SES‐ │ creating or using a │
45 │ │ SION_FAILURE │ logical session. │
46 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
47 │ │ MONGOC_ER‐ │ Failure related to │
48 │ │ ROR_CLIENT_IN‐ │ arguments passed │
49 │ │ VALID_ENCRYP‐ │ when initializing │
50 │ │ TION_ARG │ Client-Side Field │
51 │ │ │ Level Encryption. │
52 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
53 │ │ MONGOC_ER‐ │ Failure related to │
54 │ │ ROR_CLIENT_IN‐ │ Client-Side Field │
55 │ │ VALID_ENCRYP‐ │ Level Encryption. │
56 │ │ TION_STATE │ │
57 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
58 │MONGOC_ERROR_STREAM │ MONGOC_ER‐ │ DNS failure. │
59 │ │ ROR_STREAM_NAME_RES‐ │ │
60 │ │ OLUTION │ │
61 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
62 │ │ MONGOC_ER‐ │ Timeout communicat‐ │
63 │ │ ROR_STREAM_SOCKET │ ing with server, or │
64 │ │ │ connection closed. │
65 └────────────────────┴──────────────────────────────────┴────────────────────────┘
66
67 │ │ MONGOC_ER‐ │ Failed to connect │
68 │ │ ROR_STREAM_CONNECT │ to server. │
69 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
70 │MONGOC_ERROR_PROTO‐ │ MONGOC_ERROR_PROTO‐ │ Corrupt response │
71 │COL │ COL_INVALID_REPLY │ from server. │
72 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
73 │ │ MONGOC_ERROR_PROTO‐ │ The server version │
74 │ │ COL_BAD_WIRE_VERSION │ is too old or too │
75 │ │ │ new to communicate │
76 │ │ │ with the driver. │
77 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
78 │MONGOC_ERROR_CURSOR │ MONGOC_ERROR_CUR‐ │ You passed bad ar‐ │
79 │ │ SOR_INVALID_CURSOR │ guments to mon‐ │
80 │ │ │ goc_collec‐ │
81 │ │ │ tion_find_with_opts, │
82 │ │ │ or you called mon‐ │
83 │ │ │ goc_cursor_next on │
84 │ │ │ a completed or │
85 │ │ │ failed cursor, or │
86 │ │ │ the cursor timed │
87 │ │ │ out on the server. │
88 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
89 │ │ MONGOC_ER‐ │ A resume token was │
90 │ │ ROR_CHANGE_STREAM_NO_RE‐ │ not returned in a │
91 │ │ SUME_TOKEN │ document found with │
92 │ │ │ mon‐ │
93 │ │ │ goc_change_stream_next │
94 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
95 │MONGOC_ERROR_QUERY │ MONGOC_ERROR_QUERY_FAIL‐ │ Error API Version 1: │
96 │ │ URE │ Server error from com‐ │
97 │ │ │ mand or query. The │
98 │ │ │ server error message │
99 │ │ │ is in message. │
100 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
101 │MONGOC_ERROR_SERVER │ MONGOC_ERROR_QUERY_FAIL‐ │ Error API Version 2: │
102 │ │ URE │ Server error from com‐ │
103 │ │ │ mand or query. The │
104 │ │ │ server error message │
105 │ │ │ is in message. │
106 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
107 │MONGOC_ERROR_SASL │ A SASL error code. │ man sasl_errors for a │
108 │ │ │ list of codes. │
109 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
110 │MONGOC_ERROR_BSON │ MONGOC_ERROR_BSON_IN‐ │ You passed an invalid │
111 │ │ VALID │ or oversized BSON doc‐ │
112 │ │ │ ument as a parameter, │
113 │ │ │ or called mongoc_col‐ │
114 │ │ │ lection_create_index │
115 │ │ │ with invalid keys, or │
116 │ │ │ the server reply was │
117 │ │ │ corrupt. │
118 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
119 │MONGOC_ERROR_NAME‐ │ MONGOC_ERROR_NAME‐ │ You tried to create a │
120 │SPACE │ SPACE_INVALID │ collection with an in‐ │
121 │ │ │ valid name. │
122 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
123 │MONGOC_ERROR_COM‐ │ MONGOC_ERROR_COMMAND_IN‐ │ Many functions set │
124 │MAND │ VALID_ARG │ this error code when │
125 │ │ │ passed bad parameters. │
126 │ │ │ Print the error mes‐ │
127 │ │ │ sage for details. │
128 └────────────────────┴──────────────────────────────────┴────────────────────────┘
129
130
131
132
133 │ │ MONGOC_ERROR_PROTO‐ │ You tried to use a │
134 │ │ COL_BAD_WIRE_VERSION │ command option the │
135 │ │ │ server does not sup‐ │
136 │ │ │ port. │
137 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
138 │ │ MONGOC_ERROR_DUPLI‐ │ An insert or update │
139 │ │ CATE_KEY │ failed because because │
140 │ │ │ of a duplicate _id or │
141 │ │ │ other unique-index vi‐ │
142 │ │ │ olation. │
143 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
144 │ │ MONGOC_ER‐ │ The operation failed │
145 │ │ ROR_MAX_TIME_MS_EXPIRED │ because maxTimeMS ex‐ │
146 │ │ │ pired. │
147 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
148 │ │ MONGOC_ERROR_SERVER_SE‐ │ The serverId option │
149 │ │ LECTION_INVALID_ID │ for an operation con‐ │
150 │ │ │ flicts with the pinned │
151 │ │ │ server for that opera‐ │
152 │ │ │ tion's client session │
153 │ │ │ (denoted by the ses‐ │
154 │ │ │ sionId option). │
155 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
156 │MONGOC_ERROR_COM‐ │ Error code from server. │ Error API Version 1: │
157 │MAND │ │ Server error from a │
158 │ │ │ command. The server │
159 │ │ │ error message is in │
160 │ │ │ message. │
161 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
162 │MONGOC_ERROR_SERVER │ Error code from server. │ Error API Version 2: │
163 │ │ │ Server error from a │
164 │ │ │ command. The server │
165 │ │ │ error message is in │
166 │ │ │ message. │
167 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
168 │MONGOC_ERROR_COL‐ │ MONGOC_ERROR_COLLEC‐ │ Invalid or empty input │
169 │LECTION │ TION_INSERT_FAILED, MON‐ │ to mongoc_collec‐ │
170 │ │ GOC_ERROR_COLLECTION_UP‐ │ tion_insert_one, mon‐ │
171 │ │ DATE_FAILED, MONGOC_ER‐ │ goc_collection_in‐ │
172 │ │ ROR_COLLEC‐ │ sert_bulk, mongoc_col‐ │
173 │ │ TION_DELETE_FAILED. │ lection_update_one, │
174 │ │ │ mongoc_collection_up‐ │
175 │ │ │ date_many, mongoc_col‐ │
176 │ │ │ lection_replace_one, │
177 │ │ │ mongoc_collec‐ │
178 │ │ │ tion_delete_one, or │
179 │ │ │ mongoc_collec‐ │
180 │ │ │ tion_delete_many. │
181 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
182 │MONGOC_ERROR_COL‐ │ Error code from server. │ Error API Version 1: │
183 │LECTION │ │ Server error from mon‐ │
184 │ │ │ goc_collection_in‐ │
185 │ │ │ sert_one, mongoc_col‐ │
186 │ │ │ lection_insert_bulk, │
187 │ │ │ mongoc_collection_up‐ │
188 │ │ │ date_one, mongoc_col‐ │
189 │ │ │ lection_update_many, │
190 │ │ │ mongoc_collection_re‐ │
191 │ │ │ place_one, │
192 └────────────────────┴──────────────────────────────────┴────────────────────────┘
193
194
195
196
197
198
199 │MONGOC_ERROR_SERVER │ Error code from server. │ Error API Version 2: │
200 │ │ │ Server error from mon‐ │
201 │ │ │ goc_collection_in‐ │
202 │ │ │ sert_one, mongoc_col‐ │
203 │ │ │ lection_insert_bulk, │
204 │ │ │ mongoc_collection_up‐ │
205 │ │ │ date_one, mongoc_col‐ │
206 │ │ │ lection_update_many, │
207 │ │ │ mongoc_collection_re‐ │
208 │ │ │ place_one, │
209 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
210 │MONGOC_ERROR_GRIDFS │ MONGOC_ER‐ │ The GridFS file is │
211 │ │ ROR_GRIDFS_CHUNK_MISSING │ missing a document in │
212 │ │ │ its chunks collection. │
213 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
214 │ │ MONGOC_ERROR_GRIDFS_COR‐ │ A data inconsistency │
215 │ │ RUPT │ was detected in │
216 │ │ │ GridFS. │
217 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
218 │ │ MONGOC_ERROR_GRIDFS_IN‐ │ You passed a NULL │
219 │ │ VALID_FILENAME │ filename to mon‐ │
220 │ │ │ goc_gridfs_re‐ │
221 │ │ │ move_by_filename. │
222 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
223 │ │ MONGOC_ERROR_GRIDFS_PRO‐ │ You called mon‐ │
224 │ │ TOCOL_ERROR │ goc_gridfs_file_set_id │
225 │ │ │ after mon‐ │
226 │ │ │ goc_gridfs_file_save, │
227 │ │ │ or tried to write on a │
228 │ │ │ closed GridFS stream. │
229 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
230 │ │ MONGOC_ER‐ │ A GridFS file is miss‐ │
231 │ │ ROR_GRIDFS_BUCKET_FILE_NOT_FOUND │ ing from files collec‐ │
232 │ │ │ tion. │
233 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
234 │ │ MONGOC_ER‐ │ An error occurred on a │
235 │ │ ROR_GRIDFS_BUCKET_STREAM │ stream created from a │
236 │ │ │ GridFS operation like │
237 │ │ │ mon‐ │
238 │ │ │ goc_gridfs_bucket_up‐ │
239 │ │ │ load_from_stream. │
240 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
241 │MONGOC_ERROR_SCRAM │ MONGOC_ERROR_SCRAM_PROTOCOL_ER‐ │ Failure in SCRAM-SHA-1 │
242 │ │ ROR │ authentication. │
243 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
244 │MONGOC_ER‐ │ MONGOC_ERROR_SERVER_SELEC‐ │ No replica set member │
245 │ROR_SERVER_SELEC‐ │ TION_FAILURE │ or mongos is avail‐ │
246 │TION │ │ able, or none matches │
247 │ │ │ your read preference, │
248 │ │ │ or you supplied an in‐ │
249 │ │ │ valid mon‐ │
250 │ │ │ goc_read_prefs_t. │
251 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
252 │MONGOC_ER‐ │ Error code from server. │ There was a write con‐ │
253 │ROR_WRITE_CONCERN │ │ cern error or timeout │
254 │ │ │ from the server. │
255 ├────────────────────┼──────────────────────────────────┼────────────────────────┤
256 │MONGOC_ERROR_TRANS‐ │ MONGOC_ERROR_TRANSACTION_INVALID │ You attempted to start │
257 │ACTION │ │ a transaction when one │
258 │ │ │ is already in │
259 │ │ │ progress, or commit or │
260 │ │ │ abort when there is no │
261 │ │ │ transaction. │
262 └────────────────────┴──────────────────────────────────┴────────────────────────┘
263
264
265 │MONGOC_ER‐ │ Error code produced by libmon‐ │ An error occurred in │
266 │ROR_CLIENT_SIDE_EN‐ │ gocrypt. │ the library responsi‐ │
267 │CRYPTION │ │ ble for Client Side │
268 │ │ │ Encryption │
269 └────────────────────┴──────────────────────────────────┴────────────────────────┘
270
272 In some cases your application must make decisions based on what cate‐
273 gory of error the driver has returned, but these categories do not cor‐
274 respond perfectly to an error domain or code. In such cases, error la‐
275 bels provide a reliable way to determine how your application should
276 respond to an error.
277
278 Any C Driver function that has a bson_t out-parameter named reply may
279 include error labels to the reply, in the form of a BSON field named
280 "errorLabels" containing an array of strings:
281
282 { "errorLabels": [ "TransientTransactionError" ] }
283
284 Use mongoc_error_has_label to test if a reply contains a specific la‐
285 bel. See mongoc_client_session_start_transaction for example code that
286 demonstrates the use of error labels in application logic.
287
288 The following error labels are currently defined. Future versions of
289 MongoDB may introduce new labels.
290
291 TransientTransactionError
292 Within a multi-document transaction, certain errors can leave the
293 transaction in an unknown or aborted state. These include write con‐
294 flicts, primary stepdowns, and network errors. In response, the appli‐
295 cation should abort the transaction and try the same sequence of opera‐
296 tions again in a new transaction.
297
298 UnknownTransactionCommitResult
299 When mongoc_client_session_commit_transaction encounters a network er‐
300 ror or certain server errors, it is not known whether the transaction
301 was committed. Applications should attempt to commit the transaction
302 again until: the commit succeeds, the commit fails with an error not
303 labeled "UnknownTransactionCommitResult", or the application chooses to
304 give up.
305
307 The driver's error reporting began with a design flaw: when the error
308 domain is MONGOC_ERROR_COLLECTION, MONGOC_ERROR_QUERY, or MONGOC_ER‐
309 ROR_COMMAND, the error code might originate from the server or the
310 driver. An application cannot always know where an error originated,
311 and therefore cannot tell what the code means.
312
313 For example, if mongoc_collection_update_one sets the error's domain to
314 MONGOC_ERROR_COLLECTION and its code to 24, the application cannot know
315 whether 24 is the generic driver error code MONGOC_ERROR_COLLECTION_UP‐
316 DATE_FAILED or the specific server error code "LockTimeout".
317
318 To fix this flaw while preserving backward compatibility, the C Driver
319 1.4 introduces "Error API Versions". Version 1, the default Error API
320 Version, maintains the flawed behavior. Version 2 adds a new error do‐
321 main, MONGOC_ERROR_SERVER. In Version 2, error codes originating on the
322 server always have error domain MONGOC_ERROR_SERVER or MONGOC_ER‐
323 ROR_WRITE_CONCERN. When the driver uses Version 2 the application can
324 always determine the origin and meaning of error codes. New applica‐
325 tions should use Version 2, and existing applications should be updated
326 to use Version 2 as well.
327
328
329
330
331 ┌──────────────────────┬────────────────────┬─────────────────────┐
332 │Error Source │ API Version 1 │ API Version 2 │
333 ├──────────────────────┼────────────────────┼─────────────────────┤
334 │mongoc_cursor_error │ MONGOC_ERROR_QUERY │ MONGOC_ERROR_SERVER │
335 ├──────────────────────┼────────────────────┼─────────────────────┤
336 │mongoc_client_com‐ │ MONGOC_ERROR_QUERY │ MONGOC_ERROR_SERVER │
337 │mand_with_opts, │ │ │
338 │mongoc_data‐ │ │ │
339 │base_com‐ │ │ │
340 │mand_with_opts, and │ │ │
341 │other command func‐ │ │ │
342 │tions │ │ │
343 ├──────────────────────┼────────────────────┼─────────────────────┤
344 │mongoc_collec‐ │ MONGOC_ERROR_QUERY │ MONGOC_ERROR_SERVER │
345 │tion_count_with_opts │ │ │
346 │mon‐ │ │ │
347 │goc_client_get_data‐ │ │ │
348 │base_names_with_opts, │ │ │
349 │and other command │ │ │
350 │helper functions │ │ │
351 ├──────────────────────┼────────────────────┼─────────────────────┤
352 │mongoc_collection_in‐ │ MONGOC_ERROR_COM‐ │ MONGOC_ERROR_SERVER │
353 │sert_one mongoc_col‐ │ MAND │ │
354 │lection_insert_bulk │ │ │
355 │mongoc_collection_up‐ │ │ │
356 │date_one mongoc_col‐ │ │ │
357 │lection_update_many │ │ │
358 │mongoc_collection_re‐ │ │ │
359 │place_one mongoc_col‐ │ │ │
360 │lection_delete_one │ │ │
361 │mongoc_collec‐ │ │ │
362 │tion_delete_many │ │ │
363 ├──────────────────────┼────────────────────┼─────────────────────┤
364 │mongoc_bulk_opera‐ │ MONGOC_ERROR_COM‐ │ MONGOC_ERROR_SERVER │
365 │tion_execute │ MAND │ │
366 ├──────────────────────┼────────────────────┼─────────────────────┤
367 │Write-concern timeout │ MONGOC_ER‐ │ MONGOC_ER‐ │
368 │ │ ROR_WRITE_CONCERN │ ROR_WRITE_CONCERN │
369 └──────────────────────┴────────────────────┴─────────────────────┘
370
371 The Error API Versions are defined with MONGOC_ERROR_API_VERSION_LEGACY
372 and MONGOC_ERROR_API_VERSION_2. Set the version with mon‐
373 goc_client_set_error_api or mongoc_client_pool_set_error_api.
374
376 MongoDB Server Error Codes
377
379 MongoDB, Inc
380
382 2017-present, MongoDB, Inc
383
384
385
386
3871.17.6 Jun 03, 2021 MONGOC_ERRORS(3)