BSON_APPEND_UNDEFINED(3)

πŸ’… BSON_APPEND_UNDEFINED πŸ’…

okay so this is a page straight out of libbson (that's BSON_APPEND_UNDEFINED(3) if you're being formal, bestie) and it's literally all about sticking an undefined value into a BSON doc. tiny page, big lore. let's get into it 🫢


✨ SYNOPSIS ✨

here's the whole vibe, verbatim, no cap:

#define BSON_APPEND_UNDEFINED(b, key) \
   bson_append_undefined (b, key, (int) strlen (key))

bool
bson_append_undefined (bson_t *bson, const char *key, int key_length);

so you've got your cute little convenience macro up top, and the real function underneath. the macro just does the strlen math for you so you don't have to πŸ’–


πŸŽ€ PARAMETERS πŸŽ€

  • bson β€” a bson_t. that's your document, the main character of this whole operation πŸ‘‘
  • key β€” an ASCII C string holding the name of the field. yep, ASCII specifically, don't get cute with it πŸ™ˆ
  • key_length β€” how long key is, in bytes. OR you can pass -1 and it'll figure the length out itself using strlen(). lazy girl friendly ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

so bson_append_undefined() shall append a brand new element to bson, and that element is of type BSON_TYPE_UNDEFINED. slay, new element acquired πŸ’…

and here's the tea: undefined is common in Javascript. like, extremely common. it's giving ubiquitous.

BUT β€” and this is the important part, don't skip it β€” this element type is deprecated and should not be used in new code. i'm serious. do not bring it into new code. leave it in the past where it belongs πŸ’€

🚨 real talk: deprecated = don't use it in new code. it's right there in the text, bestie. i don't make the rules.

🌈 RETURNS 🌈

returns true if the operation was applied successfully. periodt. ✨

it will fail if appending the value grows bson larger than INT32_MAX. that's the hard ceiling, no negotiating πŸ”₯


🌸 AUTHOR 🌸

MongoDB, Inc β€” the icons themselves πŸ‘‘

2009-present, MongoDB, Inc.


okay that's the whole page, you ate that πŸ“ go forth and maybe... not use undefined in new code? just a thought πŸ’œ

<div align="center">⭐ libbson 2.5.6 Β· Oct 09, 2026 Β· mwah, bye bestie πŸ¦‹</div>

πŸ“¦ where this page comes from