BSON_APPEND_VALUE(3)

πŸ’… BSON_APPEND_VALUE(3) β€” the libbson era, bestie

okay so picture this: you're out here in libbson land and you need to append a value to a bson_t without knowing its type until, like, runtime. that's literally what this function is for. main character energy fr. πŸŽ€


✨ SYNOPSIS ✨

the convenient macro version (it does the strlen for you, so you don't have to):

#define BSON_APPEND_VALUE(b, key, val) \
   bson_append_value (b, key, (int) strlen (key), (val))

and the actual real one, the whole signature, exactly as it is, no cap:

bool
bson_append_value (bson_t *bson,
                   const char *key,
                   int key_length,
                   const bson_value_t *value);

πŸ¦‹ PARAMETERS πŸ¦‹

  • bson: A bson_t. the doc you're being nice to πŸ’–
  • key: An ASCII C string containing the name of the field. like the label on the box 🏷️
  • key_length: The length of key in bytes, or -1 to determine the length with strlen(). yes, -1 is the "figure it out yourself bestie" setting 🫢
  • value: A bson_value_t. this is the actual thing getting yeeted in there ✨

🌸 DESCRIPTION 🌸

Appends a new field to bson by determining the boxed type in value. so it peeks inside the bson_value_t, sees what type it's carrying, and appends accordingly β€” iconic behaviour honestly πŸ‘‘

the way that this is useful: when you want to copy fields between documents but do not know the field type until runtime. you're just a little courier moving values around, no type knowledge required, slay πŸ’…


πŸ”₯ RETURNS πŸ”₯

Returns true if the operation was applied successfully.

⚠️ heads up bestie: the function will fail if appending the value grows bson larger than INT32_MAX. like, there's a ceiling, and that's it. no notes πŸ’€

πŸ’œ AUTHOR πŸ’œ

MongoDB, Inc β€” yes that MongoDB, the whole entire company 😭


2009-present, MongoDB, Inc. β€” they've been at this a minute, fr fr.


and that's the page!! ✨ this was libbson version 2.5.6 from Oct 09, 2026 β€” go forth and append your values, bestie, you've got this πŸ¦‹πŸ’–πŸŽ€

πŸ“¦ where this page comes from