1MONGOC_ERRORS(3)                   libmongoc                  MONGOC_ERRORS(3)
2
3
4

NAME

6       mongoc_errors - Error Reporting « libmongoc
7

DESCRIPTION

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:
16          Handling Errors in libbson.
17
18
19┌────────────────────┬──────────────────────────────────┬────────────────────────────────────────────┐
20│Domain              │ Code                             │ Description                                │
21├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
22MONGOC_ERROR_CLIENT MONGOC_ER‐                       │ You tried to send a                        │
23│                    │ ROR_CLIENT_TOO_BIG               │ message larger than                        │
24│                    │                                  │ the  server's   max                        │
25│                    │                                  │ message size.                              │
26├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
27│                    │ MONGOC_ER‐                       │ Wrong  credentials,                        │
28│                    │ ROR_CLIENT_AUTHEN‐               │ or failure  sending                        │
29│                    │ TICATE                           │ or   receiving  au‐                        │
30│                    │                                  │ thentication   mes‐                        │
31│                    │                                  │ sages.                                     │
32├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
33│                    │ MONGOC_ER‐                       │ You  tried  an  TLS                        │
34│                    │ ROR_CLIENT_NO_AC‐                │ connection but  the                        │
35│                    │ CEPTABLE_PEER                    │ driver    was   not                        │
36│                    │                                  │ built with TLS.                            │
37├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
38│                    │ MONGOC_ER‐                       │ You began iterating                        │
39│                    │ ROR_CLIENT_IN_EX‐                │ an  exhaust cursor,                        │
40│                    │ HAUST                            │ then tried to begin                        │
41│                    │                                  │ another   operation                        │
42│                    │                                  │ with    the    same                        │
43│                    │                                  │ mongoc_client_t.                           │
44├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
45│                    │ MONGOC_ER‐                       │ Failure  related to                        │
46│                    │ ROR_CLIENT_SES‐                  │ creating or using a                        │
47│                    │ SION_FAILURE                     │ logical session.                           │
48├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
49│                    │ MONGOC_ER‐                       │ Failure related  to                        │
50│                    │ ROR_CLIENT_IN‐                   │ arguments    passed                        │
51│                    │ VALID_ENCRYP‐                    │ when   initializing                        │
52│                    │ TION_ARG                         │ Client-Side   Field                        │
53│                    │                                  │ Level Encryption.                          │
54├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
55│                    │ MONGOC_ER‐                       │ Failure  related to                        │
56│                    │ ROR_CLIENT_IN‐                   │ Client-Side   Field                        │
57│                    │ VALID_ENCRYP‐                    │ Level Encryption.                          │
58│                    │ TION_STATE                       │                                            │
59└────────────────────┴──────────────────────────────────┴────────────────────────────────────────────┘
60
61
62
63
64
65
66
67│                    │ MONGOC_ER‐                       │ You   attempted  to                        │
68│                    │ ROR_CLIENT_IN‐                   │ connect to  a  Mon‐                        │
69│                    │ VALID_LOAD_BALANCER              │ goDB  server behind                        │
70│                    │                                  │ a  load   balancer,                        │
71│                    │                                  │ but the server does                        │
72│                    │                                  │ not advertize  load                        │
73│                    │                                  │ balanced support.                          │
74├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
75MONGOC_ERROR_STREAM MONGOC_ER‐                       │ DNS failure.                               │
76│                    │ ROR_STREAM_NAME_RES‐             │                                            │
77│                    │ OLUTION                          │                                            │
78├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
79│                    │ MONGOC_ER‐                       │ Timeout communicat‐                        │
80│                    │ ROR_STREAM_SOCKET                │ ing with server, or                        │
81│                    │                                  │ connection closed.                         │
82├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
83│                    │ MONGOC_ER‐                       │ Failed  to  connect                        │
84│                    │ ROR_STREAM_CONNECT               │ to server.                                 │
85├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
86MONGOC_ERROR_PROTO‐ MONGOC_ERROR_PROTO‐              │ Corrupt    response                        │
87COL                 COL_INVALID_REPLY                │ from server.                               │
88├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
89│                    │ MONGOC_ERROR_PROTO‐              │ The server  version                        │
90│                    │ COL_BAD_WIRE_VERSION             │ is  too  old or too                        │
91│                    │                                  │ new to  communicate                        │
92│                    │                                  │ with the driver.                           │
93├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
94MONGOC_ERROR_CURSOR MONGOC_ERROR_CUR‐                │ You passed bad  ar‐                        │
95│                    │ SOR_INVALID_CURSOR               │ guments          to                        │
96│                    │                                  │ mongoc_collection_find_with_opts(),        │
97│                    │                                  │ or    you    called                        │
98│                    │                                  │ mongoc_cursor_next()
99│                    │                                  │ on  a  completed or                        │
100│                    │                                  │ failed  cursor,  or                        │
101│                    │                                  │ the   cursor  timed                        │
102│                    │                                  │ out on the server.                         │
103├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
104│                    │ MONGOC_ER‐                       │ A resume token was not returned  in        │
105│                    │ ROR_CHANGE_STREAM_NO_RE‐         │ a      document      found     with        │
106│                    │ SUME_TOKEN                       mongoc_change_stream_next()
107├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
108MONGOC_ERROR_QUERY  MONGOC_ERROR_QUERY_FAIL‐         Error  API  Version 1: Server error        │
109│                    │ URE                              │ from command or query.  The  server        │
110│                    │                                  │ error message is in message.               │
111├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
112MONGOC_ERROR_SERVER MONGOC_ERROR_QUERY_FAIL‐         Error API Version 2:  Server  error        │
113│                    │ URE                              │ from  command  or query. The server        │
114│                    │                                  │ error message is in message.               │
115├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
116MONGOC_ERROR_SASL   │ A SASL error code.               │ man  sasl_errors  for  a  list   of        │
117│                    │                                  │ codes.                                     │
118├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
119MONGOC_ERROR_BSON   MONGOC_ERROR_BSON_IN‐            │ You passed an invalid or  oversized        │
120│                    │ VALID                            │ BSON  document  as  a parameter, or        │
121│                    │                                  │ called                                     │
122│                    │                                  │ mongoc_collection_create_index()
123│                    │                                  │ with invalid keys,  or  the  server        │
124│                    │                                  │ reply was corrupt.                         │
125├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
126MONGOC_ERROR_NAME‐  MONGOC_ERROR_NAME‐               │ You  tried  to  create a collection        │
127SPACE               SPACE_INVALID                    │ with an invalid name.                      │
128└────────────────────┴──────────────────────────────────┴────────────────────────────────────────────┘
129
130
131
132
133MONGOC_ERROR_COM‐   MONGOC_ERROR_COMMAND_IN‐         │ Many functions set this error  code        │
134MAND                VALID_ARG                        │ when  passed  bad parameters. Print        │
135│                    │                                  │ the error message for details.             │
136├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
137│                    │ MONGOC_ERROR_PROTO‐              │ You  tried  to use a command option        │
138│                    │ COL_BAD_WIRE_VERSION             │ the server does not support.               │
139├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
140│                    │ MONGOC_ERROR_DUPLI‐              │ An  insert or update failed because        │
141│                    │ CATE_KEY                         │ because of a duplicate _id or other        │
142│                    │                                  │ unique-index violation.                    │
143├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
144│                    │ MONGOC_ER‐                       │ The operation failed  because  max‐        │
145│                    │ ROR_MAX_TIME_MS_EXPIRED          │ TimeMS expired.                            │
146├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
147│                    │ MONGOC_ERROR_SERVER_SE‐          │ The serverId option for  an  opera‐        │
148│                    │ LECTION_INVALID_ID               │ tion   conflicts  with  the  pinned        │
149│                    │                                  │ server for that operation's  client        │
150│                    │                                  │ session  (denoted  by the sessionId        
151│                    │                                  │ option).                                   │
152├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
153MONGOC_ERROR_COM‐   Error code from server.          │ Error  API  Version 1: Server error        │
154MAND                │                                  │ from a command.  The  server  error        │
155│                    │                                  │ message is in message.                     │
156├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
157MONGOC_ERROR_SERVER Error code from server.          │ Error  API  Version 2: Server error        │
158│                    │                                  │ from a command.  The  server  error        │
159│                    │                                  │ message is in message.                     │
160├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
161MONGOC_ERROR_COL‐   MONGOC_ERROR_COLLEC‐             │ Invalid    or    empty   input   to        │
162LECTION             TION_INSERT_FAILED, MON‐         mongoc_collection_insert_one(),            │
163│                    │ GOC_ERROR_COLLECTION_UP‐         mongoc_collection_insert_bulk(),           │
164│                    │ DATE_FAILED,  MONGOC_ER‐         mongoc_collection_update_one(),            │
165│                    │ ROR_COLLEC‐                      mongoc_collection_update_many(),           │
166│                    │ TION_DELETE_FAILED.              │ mongoc_collection_replace_one(),           │
167│                    │                                  │ mongoc_collection_delete_one(),  or        │
168│                    │                                  │ mongoc_collection_delete_many().           │
169├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
170MONGOC_ERROR_COL‐   Error code from server.          │ Error  API  Version 1: Server error        │
171LECTION             │                                  │ from                                       │
172│                    │                                  │ mongoc_collection_insert_one(),            │
173│                    │                                  │ mongoc_collection_insert_bulk(),           │
174│                    │                                  │ mongoc_collection_update_one(),            │
175│                    │                                  │ mongoc_collection_update_many(),           │
176│                    │                                  │ mongoc_collection_replace_one(),           │
177├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
178MONGOC_ERROR_SERVER Error code from server.          │ Error  API  Version 2: Server error        │
179│                    │                                  │ from                                       │
180│                    │                                  │ mongoc_collection_insert_one(),            │
181│                    │                                  │ mongoc_collection_insert_bulk(),           │
182│                    │                                  │ mongoc_collection_update_one(),            │
183│                    │                                  │ mongoc_collection_update_many(),           │
184│                    │                                  │ mongoc_collection_replace_one(),           │
185├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
186MONGOC_ERROR_GRIDFS MONGOC_ER‐                       │ The GridFS file is missing a  docu‐        │
187│                    │ ROR_GRIDFS_CHUNK_MISSING         │ ment in its chunks collection.             │
188├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
189│                    │ MONGOC_ERROR_GRIDFS_COR‐         │ A data inconsistency  was  detected        │
190│                    │ RUPT                             │ in GridFS.                                 │
191├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
192│                    │ MONGOC_ERROR_GRIDFS_IN‐          │ You  passed  a  NULL  filename   to        │
193│                    │ VALID_FILENAME                   mongoc_gridfs_remove_by_filename().        │
194└────────────────────┴──────────────────────────────────┴────────────────────────────────────────────┘
195
196
197
198
199│                    │ MONGOC_ERROR_GRIDFS_PRO‐         │ You                          called        │
200│                    │ TOCOL_ERROR                      mongoc_gridfs_file_set_id()   after        │
201│                    │                                  │ mongoc_gridfs_file_save(), or tried        │
202│                    │                                  │ to write on a closed GridFS stream.        │
203├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
204│                    │ MONGOC_ER‐                       │ A GridFS file is missing from files        
205│                    │ ROR_GRIDFS_BUCKET_FILE_NOT_FOUND │ collection.                                │
206├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
207│                    │ MONGOC_ER‐                       │ An  error occurred on a stream cre‐        │
208│                    │ ROR_GRIDFS_BUCKET_STREAM         │ ated from a GridFS  operation  like        │
209│                    │                                  │ mongoc_gridfs_bucket_upload_from_stream(). │
210├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
211MONGOC_ERROR_SCRAM  MONGOC_ERROR_SCRAM_PROTOCOL_ER‐  │ Failure in SCRAM-SHA-1 authentication.     │
212│                    │ ROR                              │                                            │
213├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
214MONGOC_ER‐          MONGOC_ERROR_SERVER_SELEC‐       │ No replica set member or mongos is  avail‐ │
215ROR_SERVER_SELEC‐   TION_FAILURE                     │ able,  or  none  matches your read prefer‐
216TION                │                                  │ ence,   or   you   supplied   an   invalid │
217│                    │                                  │ mongoc_read_prefs_t.                       │
218├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
219MONGOC_ER‐          Error code from server.          │ There was a write concern error or timeout
220ROR_WRITE_CONCERN   │                                  │ from the server.                           │
221├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
222MONGOC_ERROR_TRANS‐ MONGOC_ERROR_TRANSACTION_INVALID │ You attempted to start a transaction  when │
223ACTION              │                                  │ one  is  already in progress, or commit or │
224│                    │                                  │ abort when there is no transaction.        │
225├────────────────────┼──────────────────────────────────┼────────────────────────────────────────────┤
226MONGOC_ER‐          │ Error code produced  by  libmon‐ │ An error occurred in the library responsi‐ │
227ROR_CLIENT_SIDE_EN‐ │ gocrypt.                         │ ble for Client Side Encryption             │
228CRYPTION            │                                  │                                            │
229└────────────────────┴──────────────────────────────────┴────────────────────────────────────────────┘
230

ERROR LABELS

232       In some cases your application must make decisions based on what  cate‐
233       gory of error the driver has returned, but these categories do not cor‐
234       respond perfectly to an error domain or code. In such cases, error  la‐
235       bels  provide  a  reliable way to determine how your application should
236       respond to an error.
237
238       Any C Driver function that has a bson_t out-parameter named  reply  may
239       include  error  labels  to the reply, in the form of a BSON field named
240       "errorLabels" containing an array of strings:
241
242          { "errorLabels": [ "TransientTransactionError" ] }
243
244       Use mongoc_error_has_label() to test if a reply contains a specific la‐
245       bel.  See  mongoc_client_session_start_transaction()  for  example code
246       that demonstrates the use of error labels in application logic.
247
248       The following error labels are currently defined.  Future  versions  of
249       MongoDB may introduce new labels.
250
251   TransientTransactionError
252       Within  a  multi-document  transaction,  certain  errors  can leave the
253       transaction in an unknown or aborted state. These  include  write  con‐
254       flicts,  primary stepdowns, and network errors. In response, the appli‐
255       cation should abort the transaction and try the same sequence of opera‐
256       tions again in a new transaction.
257
258   UnknownTransactionCommitResult
259       When  mongoc_client_session_commit_transaction()  encounters  a network
260       error or certain server errors, it is not known whether the transaction
261       was  committed.  Applications  should attempt to commit the transaction
262       again until: the commit succeeds, the commit fails with  an  error  not
263       labeled "UnknownTransactionCommitResult", or the application chooses to
264       give up.
265

SETTING THE ERROR API VERSION

267       The driver's error reporting began with a design flaw: when  the  error
268       domain  is  MONGOC_ERROR_COLLECTION,  MONGOC_ERROR_QUERY, or MONGOC_ER‐
269       ROR_COMMAND, the error code might originate  from  the  server  or  the
270       driver.  An  application  cannot always know where an error originated,
271       and therefore cannot tell what the code means.
272
273       For example, if mongoc_collection_update_one() sets the error's  domain
274       to  MONGOC_ERROR_COLLECTION  and its code to 24, the application cannot
275       know whether 24 is the generic driver error  code  MONGOC_ERROR_COLLEC‐
276       TION_UPDATE_FAILED or the specific server error code "LockTimeout".
277
278       To  fix this flaw while preserving backward compatibility, the C Driver
279       1.4 introduces "Error API Versions". Version 1, the default  Error  API
280       Version,  maintains the flawed behavior. Version 2 adds a new error do‐
281       main, MONGOC_ERROR_SERVER. In Version 2, error codes originating on the
282       server  always  have  error  domain  MONGOC_ERROR_SERVER  or MONGOC_ER‐
283       ROR_WRITE_CONCERN. When the driver uses Version 2 the  application  can
284       always  determine  the  origin and meaning of error codes. New applica‐
285       tions should use Version 2, and existing applications should be updated
286       to use Version 2 as well.
287
288┌──────────────────────────────────────────────┬────────────────────┬─────────────────────┐
289│Error Source                                  │ API Version 1      │ API Version 2       │
290├──────────────────────────────────────────────┼────────────────────┼─────────────────────┤
291mongoc_cursor_error()MONGOC_ERROR_QUERY MONGOC_ERROR_SERVER 
292├──────────────────────────────────────────────┼────────────────────┼─────────────────────┤
293mongoc_client_command_with_opts(),            │ MONGOC_ERROR_QUERY MONGOC_ERROR_SERVER 
294mongoc_database_command_with_opts(),          │                    │                     │
295│and   other   command                         │                    │                     │
296│functions                                     │                    │                     │
297├──────────────────────────────────────────────┼────────────────────┼─────────────────────┤
298mongoc_collection_count_with_opts()MONGOC_ERROR_QUERY MONGOC_ERROR_SERVER 
299mongoc_client_get_database_names_with_opts(), │                    │                     │
300│and other command helper functions            │                    │                     │
301├──────────────────────────────────────────────┼────────────────────┼─────────────────────┤
302mongoc_collection_insert_one()MONGOC_ERROR_COM‐  MONGOC_ERROR_SERVER 
303mongoc_collection_insert_bulk()MAND               │                     │
304mongoc_collection_update_one()                │                    │                     │
305mongoc_collection_update_many()               │                    │                     │
306mongoc_collection_replace_one()               │                    │                     │
307mongoc_collection_delete_one()                │                    │                     │
308mongoc_collection_delete_many()               │                    │                     │
309├──────────────────────────────────────────────┼────────────────────┼─────────────────────┤
310mongoc_bulk_operation_execute()MONGOC_ERROR_COM‐  MONGOC_ERROR_SERVER 
311│                                              │ MAND               │                     │
312├──────────────────────────────────────────────┼────────────────────┼─────────────────────┤
313│Write-concern timeout                         │ MONGOC_ER‐         MONGOC_ER‐          
314│                                              │ ROR_WRITE_CONCERN  ROR_WRITE_CONCERN   
315└──────────────────────────────────────────────┴────────────────────┴─────────────────────┘
316
317       The Error API Versions are defined with MONGOC_ERROR_API_VERSION_LEGACY
318       and    MONGOC_ERROR_API_VERSION_2.     Set     the     version     with
319       mongoc_client_set_error_api() or mongoc_client_pool_set_error_api().
320
321       SEE ALSO:
322          MongoDB Server Error Codes
323
324

AUTHOR

326       MongoDB, Inc
327
329       2017-present, MongoDB, Inc
330
331
332
333
3341.23.1                           Oct 20, 2022                 MONGOC_ERRORS(3)
Impressum