1MONGOC_ERRORS(3)               MongoDB C Driver               MONGOC_ERRORS(3)
2
3
4

NAME

6       mongoc_errors - Error Reporting « index
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
12       error, and code for the specific error.  message  is  a  human-readable
13       error description.
14
15       See also: Handling Errors in libbson.
16
17┌────────────────────────┬─────────────────────────────────────────┬───────────────────────────────────────┐
18│Domain                  │ Code                                    │ Description                           │
19├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
20MONGOC_ERROR_CLIENT     MON‐                                    │ You tried to send a                   │
21│                        │ GOC_ERROR_CLIENT_TOO_BIG                │ message larger than                   │
22│                        │                                         │ the   server's  max                   │
23│                        │                                         │ message size.                         │
24├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
25│                        │ MON‐                                    │ Wrong  credentials,                   │
26│                        │ GOC_ERROR_CLIENT_AUTHEN‐                │ or  failure sending                   │
27│                        │ TICATE                                  │ or        receiving                   │
28│                        │                                         │ authentication mes‐                   │
29│                        │                                         │ sages.                                │
30├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
31│                        │ MON‐                                    │ You  tried  an  SSL                   │
32│                        │ GOC_ERROR_CLIENT_NO_ACCEPT‐             │ connection  but the                   │
33│                        │ ABLE_PEER                               │ driver   was    not                   │
34│                        │                                         │ built with SSL.                       │
35├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
36│                        │ MON‐                                    │ You began iterating                   │
37│                        │ GOC_ERROR_CLIENT_IN_EXHAUST             │ an  exhaust cursor,                   │
38│                        │                                         │ then tried to begin                   │
39│                        │                                         │ another   operation                   │
40│                        │                                         │ with the same  mon‐                   
41│                        │                                         │ goc_client_t.                         │
42├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
43│                        │ MONGOC_ERROR_CLIENT_SES‐                │ Failure related  to                   │
44│                        │ SION_FAILURE                            │ creating or using a                   │
45│                        │                                         │ logical session.                      │
46├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
47MONGOC_ERROR_STREAM     MON‐                                    │ DNS failure.                          │
48│                        │ GOC_ERROR_STREAM_NAME_RESO‐             │                                       │
49│                        │ LUTION                                  │                                       │
50├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
51│                        │ MONGOC_ERROR_STREAM_SOCKET              │ Timeout communicat‐                   │
52│                        │                                         │ ing with server, or                   │
53│                        │                                         │ connection closed.                    │
54├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
55│                        │ MONGOC_ERROR_STREAM_CONNECT             │ Failed  to  connect                   │
56│                        │                                         │ to server.                            │
57├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
58MONGOC_ERROR_PROTO‐     MONGOC_ERROR_PROTO‐                     │ Corrupt    response                   │
59COL                     COL_INVALID_REPLY                       │ from server.                          │
60├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
61│                        │ MONGOC_ERROR_PROTO‐                     │ The  server version                   │
62│                        │ COL_BAD_WIRE_VERSION                    │ is too old  or  too                   │
63│                        │                                         │ new  to communicate                   │
64│                        │                                         │ with the driver.                      │
65└────────────────────────┴─────────────────────────────────────────┴───────────────────────────────────────┘
66
67MONGOC_ERROR_CURSOR     MONGOC_ERROR_CUR‐                       │ You    passed   bad                   │
68│                        │ SOR_INVALID_CURSOR                      │ arguments  to  mon‐                   
69│                        │                                         │ goc_collec‐                           
70│                        │                                         │ tion_find_with_opts,                  │
71│                        │                                         │ or  you called mon‐                   
72│                        │                                         │ goc_cursor_next  on                   │
73│                        │                                         │ a    completed   or                   │
74│                        │                                         │ failed  cursor,  or                   │
75│                        │                                         │ the   cursor  timed                   │
76│                        │                                         │ out on the server.                    │
77├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
78│                        │ MON‐                                    │ A resume  token  was                  │
79│                        │ GOC_ERROR_CHANGE_STREAM_NO_RESUME_TOKEN │ not  returned  in  a                  │
80│                        │                                         │ document found  with                  │
81│                        │                                         │ mon‐                                  
82│                        │                                         │ goc_change_stream_next                
83├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
84MONGOC_ERROR_QUERY      MONGOC_ERROR_QUERY_FAILURE              Error  API  Version 1:                │
85│                        │                                         │ Server error from com‐                │
86│                        │                                         │ mand   or  query.  The                │
87│                        │                                         │ server  error  message                │
88│                        │                                         │ is in message.                        │
89├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
90MONGOC_ERROR_SERVER     MONGOC_ERROR_QUERY_FAILURE              Error  API  Version 2:                │
91│                        │                                         │ Server error from com‐                │
92│                        │                                         │ mand   or  query.  The                │
93│                        │                                         │ server  error  message                │
94│                        │                                         │ is in message.                        │
95├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
96MONGOC_ERROR_SASL       │ A SASL error code.                      │ man  sasl_errors for a                │
97│                        │                                         │ list of codes.                        │
98├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
99MONGOC_ERROR_BSON       MONGOC_ERROR_BSON_INVALID               │ You passed an  invalid                │
100│                        │                                         │ or oversized BSON doc‐                │
101│                        │                                         │ ument as a  parameter,                │
102│                        │                                         │ or  called mongoc_col‐                
103│                        │                                         │ lection_create_index                  
104│                        │                                         │ with  invalid keys, or                │
105│                        │                                         │ the server  reply  was                │
106│                        │                                         │ corrupt.                              │
107├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
108MONGOC_ERROR_NAMES‐     MONGOC_ERROR_NAMESPACE_INVALID          │ You tried to create  a                │
109PACE                    │                                         │ collection   with   an                │
110│                        │                                         │ invalid name.                         │
111├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
112MONGOC_ERROR_COM‐       MONGOC_ERROR_COMMAND_INVALID_ARG        │ Many   functions   set                │
113MAND                    │                                         │ this error  code  when                │
114│                        │                                         │ passed bad parameters.                │
115│                        │                                         │ Print the  error  mes‐                │
116│                        │                                         │ sage for details.                     │
117├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
118│                        │ MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION  │ You  tried  to  use  a                │
119│                        │                                         │ command   option   the                │
120│                        │                                         │ server  does  not sup‐                │
121│                        │                                         │ port.                                 │
122├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
123│                        │ MONGOC_ERROR_DUPLICATE_KEY              │ An  insert  or  update                │
124│                        │                                         │ failed because because                │
125│                        │                                         │ of a duplicate _id  or                │
126│                        │                                         │ other     unique-index                │
127│                        │                                         │ violation.                            │
128└────────────────────────┴─────────────────────────────────────────┴───────────────────────────────────────┘
129
130
131
132
133│                        │ MONGOC_ERROR_MAX_TIME_MS_EXPIRED        │ The  operation  failed                │
134│                        │                                         │ because      maxTimeMS                │
135│                        │                                         │ expired.                              │
136├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
137│                        │ MONGOC_ERROR_SERVER_SELEC‐              │ The   serverId  option                │
138│                        │ TION_INVALID_ID                         │ for an operation  con‐                │
139│                        │                                         │ flicts with the pinned                │
140│                        │                                         │ server for that opera‐                │
141│                        │                                         │ tion's  client session                │
142│                        │                                         │ (denoted by  the  ses‐                
143│                        │                                         │ sionId option).                       │
144├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
145MONGOC_ERROR_COM‐       Error code from server.                 │ Error API  Version  1:                │
146MAND                    │                                         │ Server  error  from  a                │
147│                        │                                         │ command.  The   server                │
148│                        │                                         │ error  message  is  in                │
149│                        │                                         │ message.                              │
150├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
151MONGOC_ERROR_SERVER     Error code from server.                 │ Error API  Version  2:                │
152│                        │                                         │ Server  error  from  a                │
153│                        │                                         │ command.  The   server                │
154│                        │                                         │ error  message  is  in                │
155│                        │                                         │ message.                              │
156├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
157MONGOC_ERROR_COL‐       MONGOC_ERROR_COLLECTION_INSERT_FAILED,  │ Invalid or empty input                │
158LECTION                 MONGOC_ERROR_COLLECTION_UPDATE_FAILED,  │ to      mongoc_collec‐                
159│                        │ MONGOC_ERROR_COLLECTION_DELETE_FAILED.  │ tion_insert_one,  mon‐                
160│                        │                                         │ goc_collec‐                           
161│                        │                                         │ tion_insert_bulk, mon‐                
162│                        │                                         │ goc_collec‐                           
163│                        │                                         │ tion_update_one,  mon‐                
164│                        │                                         │ goc_collec‐                           
165│                        │                                         │ tion_update_many, mon‐                
166│                        │                                         │ goc_collec‐                           
167│                        │                                         │ tion_replace_one, mon‐                
168│                        │                                         │ goc_collec‐                           
169│                        │                                         │ tion_delete_one,    or                │
170│                        │                                         │ mongoc_collec‐                        
171│                        │                                         │ tion_delete_many.                     │
172├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
173MONGOC_ERROR_COL‐       Error code from server.                 │ Error API  Version  1:                │
174LECTION                 │                                         │ Server error from mon‐                
175│                        │                                         │ goc_collec‐                           
176│                        │                                         │ tion_insert_one,  mon‐                
177│                        │                                         │ goc_collec‐                           
178│                        │                                         │ tion_insert_bulk, mon‐                
179│                        │                                         │ goc_collec‐                           
180│                        │                                         │ tion_update_one,  mon‐                
181│                        │                                         │ goc_collec‐                           
182│                        │                                         │ tion_update_many, mon‐                
183│                        │                                         │ goc_collec‐                           
184│                        │                                         │ tion_replace_one, mon‐                
185│                        │                                         │ goc_collec‐                           
186│                        │                                         │ tion_delete_one,    or                │
187│                        │                                         │ mongoc_collec‐                        
188│                        │                                         │ tion_delete_many.                     │
189└────────────────────────┴─────────────────────────────────────────┴───────────────────────────────────────┘
190
191
192
193
194
195
196
197
198
199MONGOC_ERROR_SERVER     Error code from server.                 │ Error  API  Version 2:                │
200│                        │                                         │ Server error from mon‐                
201│                        │                                         │ goc_collec‐                           
202│                        │                                         │ tion_insert_one,  mon‐                
203│                        │                                         │ goc_collec‐                           
204│                        │                                         │ tion_insert_bulk, mon‐                
205│                        │                                         │ goc_collec‐                           
206│                        │                                         │ tion_update_one,  mon‐                
207│                        │                                         │ goc_collec‐                           
208│                        │                                         │ tion_update_many, mon‐                
209│                        │                                         │ goc_collec‐                           
210│                        │                                         │ tion_replace_one, mon‐                
211│                        │                                         │ goc_collec‐                           
212│                        │                                         │ tion_delete_one,    or                │
213│                        │                                         │ mongoc_collec‐                        
214│                        │                                         │ tion_delete_many.                     │
215├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
216MONGOC_ERROR_GRIDFS     MONGOC_ERROR_GRIDFS_CHUNK_MISSING       │ The  GridFS  file   is                │
217│                        │                                         │ missing  a document in                │
218│                        │                                         │ its chunks collection.                │
219├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
220│                        │ MONGOC_ERROR_GRIDFS_CORRUPT             │ A  data  inconsistency                │
221│                        │                                         │ was     detected    in                │
222│                        │                                         │ GridFS.                               │
223├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
224│                        │ MONGOC_ERROR_GRIDFS_INVALID_FILENAME    │ You  passed   a   NULL                │
225│                        │                                         │ filename    to    mon‐                
226│                        │                                         │ goc_gridfs_remove_by_file‐            
227│                        │                                         │ name.                                 │
228├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
229│                        │ MONGOC_ERROR_GRIDFS_PROTOCOL_ERROR      │ You       called      mon‐            
230│                        │                                         │ goc_gridfs_file_set_id                
231│                        │                                         │ after                 mon‐            
232│                        │                                         │ goc_gridfs_file_save,   or            │
233│                        │                                         │ tried to write on a closed            │
234│                        │                                         │ GridFS stream.                        │
235├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
236│                        │ MON‐                                    │ A  GridFS  file is missing            │
237│                        │ GOC_ERROR_GRIDFS_BUCKET_FILE_NOT_FOUND  │ from files collection.                │
238├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
239│                        │ MONGOC_ERROR_GRIDFS_BUCKET_STREAM       │ An  error  occurred  on  a            │
240│                        │                                         │ stream   created   from  a            │
241│                        │                                         │ GridFS operation like mon‐            
242│                        │                                         │ goc_gridfs_bucket_upload_from_stream. │
243├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
244MONGOC_ERROR_SCRAM      MONGOC_ERROR_SCRAM_PROTOCOL_ERROR       │ Failure  in  SCRAM-SHA-1  authentica‐ │
245│                        │                                         │ tion.                                 │
246├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
247MON‐                    MONGOC_ERROR_SERVER_SELECTION_FAILURE   │ No  replica  set  member or mongos is │
248GOC_ERROR_SERVER_SELEC‐ │                                         │ available, or none matches your  read │
249TION                    │                                         │ preference,   or   you   supplied  an │
250│                        │                                         │ invalid mongoc_read_prefs_t.          │
251├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
252MONGOC_ERROR_WRITE_CON‐ Error code from server.                 │ There  was  a  write concern error or │
253CERN                    │                                         │ timeout from the server.              │
254├────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
255MONGOC_ERROR_TRANSAC‐   MONGOC_ERROR_TRANSACTION_INVALID        │ You  attempted to start a transaction │
256TION                    │                                         │ when one is already in  progress,  or │
257│                        │                                         │ commit  or  abort  when  there  is no │
258│                        │                                         │ transaction.                          │
259└────────────────────────┴─────────────────────────────────────────┴───────────────────────────────────────┘
260

ERROR LABELS

262       In some cases your application must make decisions based on what  cate‐
263       gory of error the driver has returned, but these categories do not cor‐
264       respond perfectly to an error domain or  code.  In  such  cases,  error
265       labels  provide a reliable way to determine how your application should
266       respond to an error.
267
268       Any C Driver function that has a bson_t out-parameter named  reply  may
269       include  error  labels  to the reply, in the form of a BSON field named
270       "errorLabels" containing an array of strings:
271
272          { "errorLabels": [ "TransientTransactionError" ] }
273
274       Use mongoc_error_has_label to test  if  a  reply  contains  a  specific
275       label.  See  mongoc_client_session_start_transaction  for  example code
276       that demonstrates the use of error labels in application logic.
277
278       The following error labels are currently defined.  Future  versions  of
279       MongoDB may introduce new labels.
280
281   TransientTransactionError
282       Within  a  multi-document  transaction,  certain  errors  can leave the
283       transaction in an unknown or aborted state. These  include  write  con‐
284       flicts,  primary stepdowns, and network errors. In response, the appli‐
285       cation should abort the transaction and try the same sequence of opera‐
286       tions again in a new transaction.
287
288   UnknownTransactionCommitResult
289       When   mongoc_client_session_commit_transaction  encounters  a  network
290       error or certain server errors, it is not known whether the transaction
291       was  committed.  Applications  should attempt to commit the transaction
292       again until: the commit succeeds, the commit fails with  an  error  not
293       labeled "UnknownTransactionCommitResult", or the application chooses to
294       give up.
295

SETTING THE ERROR API VERSION

297       The driver's error reporting began with a design flaw: when  the  error
298       domain   is   MONGOC_ERROR_COLLECTION,   MONGOC_ERROR_QUERY,   or  MON‐
299       GOC_ERROR_COMMAND, the error code might originate from  the  server  or
300       the  driver.  An  application  cannot always know where an error origi‐
301       nated, and therefore cannot tell what the code means.
302
303       For example, if mongoc_collection_update_one sets the error's domain to
304       MONGOC_ERROR_COLLECTION and its code to 24, the application cannot know
305       whether 24  is  the  generic  driver  error  code  MONGOC_ERROR_COLLEC‐
306       TION_UPDATE_FAILED or the specific server error code "LockTimeout".
307
308       To  fix this flaw while preserving backward compatibility, the C Driver
309       1.4 introduces "Error API Versions". Version 1, the default  Error  API
310       Version,  maintains  the  flawed  behavior.  Version 2 adds a new error
311       domain, MONGOC_ERROR_SERVER. In Version 2, error codes  originating  on
312       the  server  always  have  error  domain  MONGOC_ERROR_SERVER  or  MON‐
313       GOC_ERROR_WRITE_CONCERN. When the driver uses Version 2 the application
314       can  always determine the origin and meaning of error codes. New appli‐
315       cations should use Version  2,  and  existing  applications  should  be
316       updated to use Version 2 as well.
317
318        ┌──────────────────────┬──────────────────────┬──────────────────────┐
319        │Error Source          │ API Version 1        │ API Version 2        │
320        ├──────────────────────┼──────────────────────┼──────────────────────┤
321mongoc_cursor_error   MONGOC_ERROR_QUERY   MONGOC_ERROR_SERVER  
322        └──────────────────────┴──────────────────────┴──────────────────────┘
323
324
325
326
327
328
329
330
331mongoc_client_com‐    MONGOC_ERROR_QUERY   MONGOC_ERROR_SERVER  
332mand_with_opts,       │                      │                      │
333mongoc_data‐          │                      │                      │
334base_com‐             │                      │                      │
335mand_with_opts, and   │                      │                      │
336        │other command func‐   │                      │                      │
337        │tions                 │                      │                      │
338        ├──────────────────────┼──────────────────────┼──────────────────────┤
339mongoc_collec‐        MONGOC_ERROR_QUERY   MONGOC_ERROR_SERVER  
340tion_count_with_opts  │                      │                      │
341mon‐                  │                      │                      │
342goc_client_get_data‐  │                      │                      │
343base_names_with_opts, │                      │                      │
344        │and  other  command   │                      │                      │
345        │helper functions      │                      │                      │
346        ├──────────────────────┼──────────────────────┼──────────────────────┤
347mongoc_collec‐        MONGOC_ERROR_COM‐    MONGOC_ERROR_SERVER  
348tion_insert_one  mon‐ MAND                 │                      │
349goc_collec‐           │                      │                      │
350tion_insert_bulk mon‐ │                      │                      │
351goc_collec‐           │                      │                      │
352tion_update_one  mon‐ │                      │                      │
353goc_collec‐           │                      │                      │
354tion_update_many mon‐ │                      │                      │
355goc_collec‐           │                      │                      │
356tion_replace_one mon‐ │                      │                      │
357goc_collec‐           │                      │                      │
358tion_delete_one  mon‐ │                      │                      │
359goc_collec‐           │                      │                      │
360tion_delete_many      │                      │                      │
361        ├──────────────────────┼──────────────────────┼──────────────────────┤
362mongoc_bulk_opera‐    MONGOC_ERROR_COM‐    MONGOC_ERROR_SERVER  
363tion_execute          MAND                 │                      │
364        ├──────────────────────┼──────────────────────┼──────────────────────┤
365        │Write-concern timeout │ MON‐                 MON‐                 
366        │                      │ GOC_ERROR_WRITE_CON‐ GOC_ERROR_WRITE_CON‐ 
367        │                      │ CERN                 CERN                 
368        └──────────────────────┴──────────────────────┴──────────────────────┘
369
370       The Error API Versions are defined with MONGOC_ERROR_API_VERSION_LEGACY
371       and   MONGOC_ERROR_API_VERSION_2.   Set   the   version    with    mon‐
372       goc_client_set_error_api or mongoc_client_pool_set_error_api.
373

SEE ALSO

375       MongoDB Server Error Codes
376

AUTHOR

378       MongoDB, Inc
379
381       2017-present, MongoDB, Inc
382
383
384
385
3861.15.2                           Nov 06, 2019                 MONGOC_ERRORS(3)
Impressum