MONGOC_ERRORS(3)
π MONGOC_ERRORS(3) π
libmongoc manual page, API section β Β« libmongoc - API. bestie, this is the error-code lore, and it's honestly iconic.
β¨ DESCRIPTION β¨
okay so many C Driver functions report errors by returning false or -1 and filling out a bson_error_t structure with an error domain, an error code, and a message. Use domain to figure out which subsystem generated the error, and code for the specific error. message is a human-readable error description. literally that's the whole vibe.
πΈ SEE ALSO πΈ
SEE ALSO: Handling Errors in libbson.
now the big code table, grouped by domain so it's readable β every row is here, no cap:
MONGOC_ERROR_CLIENTβ the client domain:MONGOC_ERROR_CLIENT_TOO_BIGβ you tried to send a message larger than the server's max message size. too big, bestie πMONGOC_ERROR_CLIENT_AUTHENTICATEβ wrong credentials, or failure sending or receiving authentication messages.MONGOC_ERROR_CLIENT_NO_ACCEPTABLE_PEERβ you tried a TLS connection but the driver was not built with TLS.MONGOC_ERROR_CLIENT_IN_EXHAUSTβ you began iterating an exhaust cursor, then tried to begin another operation with the samemongoc_client_t.MONGOC_ERROR_CLIENT_SESSION_FAILUREβ failure related to creating or using a logical session.MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_ARGβ failure related to arguments passed when initializing In-Use Encryption.MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_STATEβ failure related to In-Use Encryption.MONGOC_ERROR_CLIENT_INVALID_LOAD_BALANCERβ you attempted to connect to a MongoDB server behind a load balancer, but the server does not advertize load balanced support.MONGOC_ERROR_CLIENT_NOT_READYβ you attempted to create a client but did not previously callmongoc_init().
MONGOC_ERROR_STREAMβ the stream domain:MONGOC_ERROR_STREAM_NAME_RESOLUTIONβ DNS failure.MONGOC_ERROR_STREAM_SOCKETβ timeout communicating with server, or connection closed.MONGOC_ERROR_STREAM_CONNECTβ failed to connect to server.
MONGOC_ERROR_PROTOCOLβ the protocol domain:MONGOC_ERROR_PROTOCOL_INVALID_REPLYβ corrupt response from server. πMONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSIONβ the server version is too old or too new to communicate with the driver.
okay so the table keeps going, bestie β buckle up, we're still in the error-domain zone π
MONGOC_ERROR_CURSORMONGOC_ERROR_CURSOR_INVALID_CURSORβ this one's giving βyou did too muchβ π you passed bad arguments tomongoc_collection_find_with_opts(), or you calledmongoc_cursor_next()on a cursor that's already completed or has failed, or the cursor timed out on the server. that's it, that's the whole vibe check fail.MONGOC_ERROR_CHANGE_STREAM_NO_RESUME_TOKENβ a resume token was not returned in a document found withmongoc_change_stream_next()π«Ά (the domain cell was blank in the original, so yes, it's nesting underMONGOC_ERROR_CURSORβ iykyk)
MONGOC_ERROR_QUERYMONGOC_ERROR_QUERY_FAILUREβ Error API Version 1: server error from a command or query π₯ the server error message is inmessage.
MONGOC_ERROR_SERVERMONGOC_ERROR_QUERY_FAILUREβ Error API Version 2: server error from a command or query β¨ the server error message is inmessage. (yes, same code name, different domain β the API version is literally the whole plot twist π)
MONGOC_ERROR_SASLA SASL error code.β not me handing you off to another manpage, but fr:man sasl_errorsfor a list of codes π
MONGOC_ERROR_BSONMONGOC_ERROR_BSON_INVALIDβ you passed an invalid or oversized BSON document as a parameter, or the server reply was corrupt π no cap, check your docs.
MONGOC_ERROR_NAMESPACEMONGOC_ERROR_NAMESPACE_INVALIDβ you tried to create a collection with an invalid name π she said βpick a better nameβ and honestly? valid.
MONGOC_ERROR_COMMANDMONGOC_ERROR_COMMAND_INVALID_ARGβ many functions set this error code when passed bad parameters. print the error message for details π«Ά like, the details are literally right there bestie, read them.MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSIONβ you tried to use a command option the server does not support β the server said βwe don't do that hereβ and honestly it's not wrong.MONGOC_ERROR_DUPLICATE_KEYβ an insert or update failed because of a duplicate_idor other unique-index violation π she's already taken. iconic, but taken.MONGOC_ERROR_MAX_TIME_MS_EXPIREDβ the operation failed becausemaxTimeMSexpired β° time said βgirl, bye.βMONGOC_ERROR_SERVER_SELECTION_INVALID_IDβ theserverIdoption for an operation conflicts with the pinned server for that operation's client session (denoted by thesessionIdoption) π¦ two servers, one session, zero chill.
MONGOC_ERROR_COMMANDError code from server.β Error API Version 1: server error from a command π₯ the server error message is inmessage.
MONGOC_ERROR_SERVERError code from server.β Error API Version 2: server error from a command π₯ the server error message is inmessage.
and yes, you clocked it β MONGOC_ERROR_QUERY_FAILURE and the MONGOC_ERROR_COMMAND + βError code from server.β rows show up twice on purpose, once per Error API version π don't merge them in your head, that's how the docs get messy bestie.
MONGOC_ERROR_COLLECTIONποΈ β bestie this one's got a whole little squad of codes under it:MONGOC_ERROR_COLLECTION_INSERT_FAILED,MONGOC_ERROR_COLLECTION_UPDATE_FAILED,MONGOC_ERROR_COLLECTION_DELETE_FAILEDβ literally means the input you handed tomongoc_collection_insert_one(),mongoc_collection_insert_many(),mongoc_collection_update_one(),mongoc_collection_update_many(),mongoc_collection_replace_one(),mongoc_collection_delete_one(), ormongoc_collection_delete_many()was invalid or empty. check ur args, babe π- Error code from server β Error API Version 1 vibes: a server error that came back from
mongoc_collection_insert_one(),mongoc_collection_insert_many(),mongoc_collection_update_one(),mongoc_collection_update_many(),mongoc_collection_replace_one(),
MONGOC_ERROR_SERVERπ₯οΈ β ok so this one's giving similar energy but different lore:- Error code from server β Error API Version 2 flavor: a server error straight from
mongoc_collection_insert_one(),mongoc_collection_insert_many(),mongoc_collection_update_one(),mongoc_collection_update_many(),mongoc_collection_replace_one(),
- Error code from server β Error API Version 2 flavor: a server error straight from
MONGOC_ERROR_GRIDFSπ β the whole GridFS drama collection, lowkey iconic:MONGOC_ERROR_GRIDFS_CHUNK_MISSINGβ the GridFS file is missing a document in its chunks collection π like it literally lost a piece of itselfMONGOC_ERROR_GRIDFS_CORRUPTβ a data inconsistency was detected in GridFS. something's not adding up bestie πMONGOC_ERROR_GRIDFS_INVALID_FILENAMEβ you passed aNULLfilename tomongoc_gridfs_remove_by_filename(). yeah that'll do it πMONGOC_ERROR_GRIDFS_PROTOCOL_ERRORβ you calledmongoc_gridfs_file_set_id()aftermongoc_gridfs_file_save(), or tried to write on a closed GridFS stream. rude of you honestlyMONGOC_ERROR_GRIDFS_BUCKET_FILE_NOT_FOUNDβ a GridFS file is missing from files collection. gone. vanished. not found bestie π«₯MONGOC_ERROR_GRIDFS_BUCKET_STREAMβ an error occurred on a stream created from a GridFS operation likemongoc_gridfs_bucket_upload_from_stream()
MONGOC_ERROR_SCRAMπMONGOC_ERROR_SCRAM_PROTOCOL_ERRORβ failure in SCRAM-SHA-1 or SCRAM-SHA-256 authentication. auth said nope β¨
MONGOC_ERROR_SERVER_SELECTIONπ―MONGOC_ERROR_SERVER_SELECTION_FAILUREβ no replica set member or mongos is available, or none matches your read preference, or you supplied an invalidmongoc_read_prefs_t. it's giving "everyone's busy rn" energy tbh
MONGOC_ERROR_WRITE_CONCERNβοΈ- Error code from server β there was a write concern error or timeout from the server. the server said "mmm not right now" π
MONGOC_ERROR_TRANSACTIONπMONGOC_ERROR_TRANSACTION_INVALIDβ you attempted to start a transaction when one is already in progress, or commit or abort when there is no transaction. pick a lane bestie, you can't do both π
MONGOC_ERROR_CLIENT_SIDE_ENCRYPTIONπ΅οΈ- Error code produced by libmongocrypt β an error occurred in the library responsible for In-Use Encryption
MONGOC_ERROR_AZUREβMONGOC_ERROR_KMS_SERVER_HTTPβ an Azure HTTP service responded with an error status πMONGOC_ERROR_AZUREβMONGOC_ERROR_KMS_SERVER_BAD_JSONβ an Azure service responded with invalid JSON data πMONGOC_ERROR_GCPβMONGOC_ERROR_KMS_SERVER_HTTPβ a GCP HTTP service responded with an error statusMONGOC_ERROR_GCPβMONGOC_ERROR_KMS_SERVER_BAD_JSONβ a GCP service responded with invalid JSON data
πΈ ERROR LABELS πΈ
Okay so sometimes your app has to make decisions based on what category of error the driver handed back, but those categories don't map perfectly onto an error domain or code. That's exactly when error labels come through β they're the reliable way to figure out how your application should respond to an error. Periodt.
Any C Driver function that has a bson_t out-parameter named reply may include error labels in that reply, as a BSON field named "errorLabels" containing an array of strings:
{ "errorLabels": [ "TransientTransactionError" ] }
Use mongoc_error_has_label() to test if a reply contains a specific label. See mongoc_client_session_start_transaction() for example code that demonstrates the use of error labels in application logic. iykyk π
The following error labels are currently defined. Future versions of MongoDB may introduce new labels.
π« TransientTransactionError π«
Inside a multi-document transaction, certain errors can leave the transaction in an unknown or aborted state. These include write conflicts, primary stepdowns, and network errors. In response, the application should abort the transaction and try the same sequence of operations again in a new transaction. No cap β that's the move. π«Ά
π UnknownTransactionCommitResult π
When mongoc_client_session_commit_transaction() encounters a network error or certain server errors, it is not known whether the transaction was committed. Applications should attempt to commit the transaction again until: the commit succeeds, the commit fails with an error not labeled "UnknownTransactionCommitResult", or the application chooses to give up. Lowkey stressful, but that's the rule. π
π₯ SETTING THE ERROR API VERSION π₯
The driver's error reporting began with a design flaw: when the error domain is MONGOC_ERROR_COLLECTION, MONGOC_ERROR_QUERY, or MONGOC_ERROR_COMMAND, the error code might originate from the server or the driver. An application cannot always know where an error originated, and therefore cannot tell what the code means. It's giving mystery box, and not in a fun way. π
For example, if mongoc_collection_update_one() sets the error's domain to MONGOC_ERROR_COLLECTION and its code to 24, the application cannot know whether 24 is the generic driver error code MONGOC_ERROR_COLLECTION_UPDATE_FAILED or the specific server error code "LockTimeout".
To fix this flaw while preserving backward compatibility, the C Driver 1.4 introduces "Error API Versions". Version 1, the default Error API Version, maintains the flawed behavior. Version 2 adds a new error domain, MONGOC_ERROR_SERVER. In Version 2, error codes originating on the server always have error domain MONGOC_ERROR_SERVER or MONGOC_ERROR_WRITE_CONCERN. When the driver uses Version 2 the application can always determine the origin and meaning of error codes. New applications should use Version 2, and existing applications should be updated to use Version 2 as well. Slay. β¨
Vibe check on the whole mapping, bestie β here's every row:
mongoc_cursor_error()β API Version 1:MONGOC_ERROR_QUERY; API Version 2:MONGOC_ERROR_SERVERmongoc_client_command_with_opts(),mongoc_database_command_with_opts(), and other command functions β API Version 1:MONGOC_ERROR_QUERY; API Version 2:MONGOC_ERROR_SERVERmongoc_client_get_database_names_with_opts()and other command helper functions β API Version 1:MONGOC_ERROR_QUERY; API Version 2:MONGOC_ERROR_SERVERmongoc_collection_insert_one(),mongoc_collection_insert_many(),mongoc_collection_update_one(),mongoc_collection_update_many(),mongoc_collection_replace_one(),mongoc_collection_delete_one(),mongoc_collection_delete_many()β API Version 1:MONGOC_ERROR_COMMAND; API Version 2:MONGOC_ERROR_SERVERmongoc_bulk_operation_execute()β API Version 1:MONGOC_ERROR_COMMAND; API Version 2:MONGOC_ERROR_SERVER- Write-concern timeout β API Version 1:
MONGOC_ERROR_WRITE_CONCERN; API Version 2:MONGOC_ERROR_WRITE_CONCERN
The Error API Versions are defined with MONGOC_ERROR_API_VERSION_LEGACY and MONGOC_ERROR_API_VERSION_2. Set the version with mongoc_client_set_error_api() or mongoc_client_pool_set_error_api().
π SEE ALSO π
- MongoDB Server Error Codes
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
π That's a wrap on MONGOC_ERRORS(3), bestie β MongoDB C Driver docs, version 2.5.6, dated Oct 09, 2026. Periodt. π
β¨
π¦ where this page comes from
- epel 10: mongo-c-driver-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms