1MONGOC_ERRORS(3)                   libmongoc                  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├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
47│                              │ MON‐                                    │ Failure related  to                   │
48│                              │ GOC_ERROR_CLIENT_INVALID_ENCRYP‐        │ arguments    passed                   │
49│                              │ TION_ARG                                │ when   initializing                   │
50│                              │                                         │ Client-Side   Field                   │
51│                              │                                         │ Level Encryption.                     │
52├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
53│                              │ MON‐                                    │ Failure related  to                   │
54│                              │ GOC_ERROR_CLIENT_INVALID_ENCRYP‐        │ Client-Side   Field                   │
55│                              │ TION_STATE                              │ Level Encryption.                     │
56├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
57MONGOC_ERROR_STREAM           MONGOC_ERROR_STREAM_NAME_RESOLU‐        │ DNS failure.                          │
58│                              │ TION                                    │                                       │
59├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
60│                              │ MONGOC_ERROR_STREAM_SOCKET              │ Timeout communicat‐                   │
61│                              │                                         │ ing with server, or                   │
62│                              │                                         │ connection closed.                    │
63└──────────────────────────────┴─────────────────────────────────────────┴───────────────────────────────────────┘
64
65
66
67│                              │ MONGOC_ERROR_STREAM_CONNECT             │ Failed  to  connect                   │
68│                              │                                         │ to server.                            │
69├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
70MONGOC_ERROR_PROTO‐           MONGOC_ERROR_PROTO‐                     │ Corrupt    response                   │
71COL                           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├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
78MONGOC_ERROR_CURSOR           MONGOC_ERROR_CURSOR_INVALID_CUR‐        │ You   passed    bad                   │
79│                              │ SOR                                     │ arguments  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│                              │ MON‐                                    │ A  resume  token was                  │
90│                              │ GOC_ERROR_CHANGE_STREAM_NO_RESUME_TOKEN │ not  returned  in  a                  │
91│                              │                                         │ document  found with                  │
92│                              │                                         │ mon‐                                  
93│                              │                                         │ goc_change_stream_next                
94├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
95MONGOC_ERROR_QUERY            MONGOC_ERROR_QUERY_FAILURE              Error API  Version  1:                │
96│                              │                                         │ Server error from com‐                │
97│                              │                                         │ mand  or  query.   The                │
98│                              │                                         │ server  error  message                │
99│                              │                                         │ is in message.                        │
100├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
101MONGOC_ERROR_SERVER           MONGOC_ERROR_QUERY_FAILURE              Error API  Version  2:                │
102│                              │                                         │ Server error from com‐                │
103│                              │                                         │ mand  or  query.   The                │
104│                              │                                         │ server  error  message                │
105│                              │                                         │ is in message.                        │
106├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
107MONGOC_ERROR_SASL             │ A SASL error code.                      │ man sasl_errors for  a                │
108│                              │                                         │ list of codes.                        │
109├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
110MONGOC_ERROR_BSON             MONGOC_ERROR_BSON_INVALID               │ You  passed an invalid                │
111│                              │                                         │ 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├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
119MONGOC_ERROR_NAMES‐           MONGOC_ERROR_NAMESPACE_INVALID          │ You  tried to create a                │
120PACE                          │                                         │ collection   with   an                │
121│                              │                                         │ invalid name.                         │
122├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
123MONGOC_ERROR_COM‐             MONGOC_ERROR_COMMAND_INVALID_ARG        │ Many   functions   set                │
124MAND                          │                                         │ 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_PROTOCOL_BAD_WIRE_VERSION  │ You  tried  to  use  a                │
134│                              │                                         │ command   option   the                │
135│                              │                                         │ server does  not  sup‐                │
136│                              │                                         │ port.                                 │
137├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
138│                              │ MONGOC_ERROR_DUPLICATE_KEY              │ An  insert  or  update                │
139│                              │                                         │ failed because because                │
140│                              │                                         │ of  a duplicate _id or                │
141│                              │                                         │ other     unique-index                │
142│                              │                                         │ violation.                            │
143├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
144│                              │ MONGOC_ERROR_MAX_TIME_MS_EXPIRED        │ The  operation  failed                │
145│                              │                                         │ because      maxTimeMS                │
146│                              │                                         │ expired.                              │
147├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
148│                              │ MONGOC_ERROR_SERVER_SELEC‐              │ The  serverId   option                │
149│                              │ TION_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├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
156MONGOC_ERROR_COM‐             Error code from server.                 │ Error  API  Version 1:                │
157MAND                          │                                         │ Server  error  from  a                │
158│                              │                                         │ command.   The  server                │
159│                              │                                         │ error  message  is  in                │
160│                              │                                         │ message.                              │
161├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
162MONGOC_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├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
168MONGOC_ERROR_COL‐             MONGOC_ERROR_COLLECTION_INSERT_FAILED,  │ Invalid or empty input                │
169LECTION                       MONGOC_ERROR_COLLECTION_UPDATE_FAILED,  │ to      mongoc_collec‐                
170│                              │ MONGOC_ERROR_COLLECTION_DELETE_FAILED.  │ tion_insert_one,  mon‐                
171│                              │                                         │ goc_collec‐                           
172│                              │                                         │ tion_insert_bulk, mon‐                
173│                              │                                         │ goc_collec‐                           
174│                              │                                         │ tion_update_one,  mon‐                
175│                              │                                         │ goc_collec‐                           
176│                              │                                         │ tion_update_many, mon‐                
177│                              │                                         │ goc_collec‐                           
178│                              │                                         │ tion_replace_one, mon‐                
179│                              │                                         │ goc_collec‐                           
180│                              │                                         │ tion_delete_one,    or                │
181│                              │                                         │ mongoc_collec‐                        
182│                              │                                         │ tion_delete_many.                     │
183├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
184MONGOC_ERROR_COL‐             Error code from server.                 │ Error  API  Version 1:                │
185LECTION                       │                                         │ Server error from mon‐                
186│                              │                                         │ goc_collec‐                           
187│                              │                                         │ tion_insert_one,  mon‐                
188│                              │                                         │ goc_collec‐                           
189│                              │                                         │ tion_insert_bulk, mon‐                
190│                              │                                         │ goc_collec‐                           
191│                              │                                         │ tion_update_one,  mon‐                
192│                              │                                         │ goc_collec‐                           
193│                              │                                         │ tion_update_many, mon‐                
194│                              │                                         │ goc_collec‐                           
195│                              │                                         │ tion_replace_one,                     │
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,                     │
211├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
212MONGOC_ERROR_GRIDFS           MONGOC_ERROR_GRIDFS_CHUNK_MISSING       │ The   GridFS  file  is                │
213│                              │                                         │ missing a document  in                │
214│                              │                                         │ its chunks collection.                │
215├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
216│                              │ MONGOC_ERROR_GRIDFS_CORRUPT             │ A  data  inconsistency                │
217│                              │                                         │ was    detected     in                │
218│                              │                                         │ GridFS.                               │
219├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
220│                              │ MONGOC_ERROR_GRIDFS_INVALID_FILENAME    │ You   passed   a  NULL                │
221│                              │                                         │ filename    to    mon‐                
222│                              │                                         │ goc_gridfs_remove_by_file‐            
223│                              │                                         │ name.                                 │
224├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
225│                              │ MONGOC_ERROR_GRIDFS_PROTOCOL_ERROR      │ You      called       mon‐            
226│                              │                                         │ goc_gridfs_file_set_id                
227│                              │                                         │ after                 mon‐            
228│                              │                                         │ goc_gridfs_file_save,   or            │
229│                              │                                         │ tried to write on a closed            │
230│                              │                                         │ GridFS stream.                        │
231├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
232│                              │ MON‐                                    │ A GridFS file  is  missing            │
233│                              │ GOC_ERROR_GRIDFS_BUCKET_FILE_NOT_FOUND  │ from files collection.                │
234├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
235│                              │ MONGOC_ERROR_GRIDFS_BUCKET_STREAM       │ An  error  occurred  on  a            │
236│                              │                                         │ stream  created   from   a            │
237│                              │                                         │ GridFS operation like mon‐            
238│                              │                                         │ goc_gridfs_bucket_upload_from_stream. │
239├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
240MONGOC_ERROR_SCRAM            MONGOC_ERROR_SCRAM_PROTOCOL_ERROR       │ Failure  in  SCRAM-SHA-1  authentica‐ │
241│                              │                                         │ tion.                                 │
242├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
243MON‐                          MONGOC_ERROR_SERVER_SELECTION_FAILURE   │ No replica set member  or  mongos  is │
244GOC_ERROR_SERVER_SELEC‐       │                                         │ available,  or none matches your read │
245TION                          │                                         │ preference,  or   you   supplied   an │
246│                              │                                         │ invalid mongoc_read_prefs_t.          │
247├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
248MONGOC_ERROR_WRITE_CON‐       Error code from server.                 │ There was a write  concern  error  or │
249CERN                          │                                         │ timeout from the server.              │
250├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
251MONGOC_ERROR_TRANSAC‐         MONGOC_ERROR_TRANSACTION_INVALID        │ You attempted to start a  transaction │
252TION                          │                                         │ when  one  is already in progress, or │
253│                              │                                         │ commit or  abort  when  there  is  no │
254│                              │                                         │ transaction.                          │
255├──────────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────┤
256MON‐                          │ Error code produced by libmongocrypt.   │ An  error  occurred  in  the  library │
257GOC_ERROR_CLIENT_SIDE_ENCRYP‐ │                                         │ responsible for Client  Side  Encryp‐ │
258TION                          │                                         │ tion                                  │
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.16.2                           Feb 25, 2020                 MONGOC_ERRORS(3)
Impressum