MONGOC_CLIENT_...YPTION_ENCRYPT(3)
π mongoc_client_encryption_encrypt π
okay bestie, welcome to the libmongoc manual, specifically the page for mongoc_client_encryption_encrypt β yes the header got chopped in the terminal like a bad screenshot, but that's the one. she does explicit encryption, and honestly? iconic behavior. let's get into it π«Ά
β¨ SYNOPSIS β¨
bool
mongoc_client_encryption_encrypt (
mongoc_client_encryption_t *client_encryption,
const bson_value_t *value,
mongoc_client_encryption_encrypt_opts_t *opts,
bson_value_t *ciphertext,
bson_error_t *error);
πΈ DESCRIPTION πΈ
so what does she actually do? she performs explicit encryption. that's the whole vibe. π
ciphertext is always initialized β even on failure, no cap, she never leaves you hanging with garbage memory. but bestie listen: the caller must call bson_value_destroy() to free it. literally your job, not hers. don't ghost your cleanup π«Ά
now, the important part π β to insert or query with an "Indexed" or "Range" encrypted payload, you use a mongoc_client_t that's configured with mongoc_auto_encryption_opts_t.
that mongoc_auto_encryption_opts_t may be configured to bypass query analysis with mongoc_auto_encryption_opts_set_bypass_query_analysis().
but it must not be configured to bypass automatic encryption with mongoc_auto_encryption_opts_set_bypass_auto_encryption(). π« like, absolutely not, that's the one thing you can't do here.
β οΈ read that again bestie β "may bypass query analysis" = fine, "must not bypass automatic encryption" = do not. they are NOT the same thing and mixing them up is a whole mess. π
to insert with a Range payload, mongoc_client_encryption_encrypt_range_opts_t must be set in opts. no shortcuts β¨
and to query with a Range payload? that's a whole different function β use mongoc_client_encryption_encrypt_expression(). different girl, different job π
π PARAMETERS π
client_encryptionβ amongoc_client_encryption_t. the main character of this function β¨valueβ the value to encrypt. the secret. the tea. πoptsβ amongoc_client_encryption_encrypt_opts_t. this is where you set your Range opts if you're doing the Range thing.ciphertextβ abson_value_tthat holds the resulting ciphertext β which is a BSON binary with subtype 6, iykyk π¦errorβ abson_error_tthat gets set on failure. she'll tell you what went wrong π
β RETURNS β
returns true if it worked β slay, we love a success π
returns false and sets error otherwise. so like, always check. always. π
π SEE ALSO π
mongoc_client_encryption_encrypt_opts_tmongoc_client_enable_auto_encryption()mongoc_client_decryption_decrypt()mongoc_client_encryption_encrypt_expression()
go read those next, they're lowkey required reading for the full lore π
π AUTHOR π
MongoDB, Inc β the icon, the legend, the whole team π«Ά
π COPYRIGHT π
2009-present, MongoDB, Inc. β periods and all, we respect the paperwork π
and that's a wrap, bestie!! this page is from libmongoc version 2.5.6, date stamped Oct 09, 202 (yes the terminal ate the rest of the year, she's mysterious like that πβ¨). go forth, encrypt explicitly, and please call bson_value_destroy(). mwah ππ
π¦ 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