BSON_APPEND_OID(3)

πŸ’… BSON_APPEND_OID(3) β€” libbson, bestie

okay so you're here because you wanna shove an ObjectId into a BSON document and you want the group chat to explain it. no worries, this is literally the libbson manual page for BSON_APPEND_OID, and it's giving "tiny function, big slay". ✨


πŸŽ€ SYNOPSIS

Here's the macro, and here's the actual function it wraps β€” both, verbatim, because we don't gatekeep:

#define BSON_APPEND_OID(b, key, val) \
   bson_append_oid (b, key, (int) strlen (key), val)

bool
bson_append_oid (bson_t *bson,
                 const char *key,
                 int key_length,
                 const bson_oid_t *oid);

🌸 PARAMETERS

  • bson β€” a bson_t. that's your document, the main character 🫢
  • key β€” an ASCII C string with the field name. ASCII specifically, bestie, don't get cute with it.
  • key_length β€” how long key is, in bytes. pass -1 and it'll figure the length out with strlen() for you πŸ™ˆ
  • oid β€” a bson_oid_t. yes. one of those.

πŸ¦‹ DESCRIPTION

bson_append_oid() appends a brand-new element to bson, and the type of that element is BSON_TYPE_OID. that's it, that's the whole vibe. πŸ’…

⚠️ oid MUST be a pointer to a bson_oid_t. like, non-negotiable. no cap.

⭐ RETURNS

returns true if the operation went through successfully β€” slay, it worked πŸŽ‰

it will fail if appending oid grows bson larger than INT32_MAX. yeah. there's a ceiling. iconic but firm. 😭


πŸ‘‘ AUTHOR

MongoDB, Inc

2009-present, MongoDB, Inc.


and that's the whole page, bestie β€” go forth and append those OIDs 🧚

sign-off tingz: this was libbson version 2.5.6, dated Oct 09, 2026. mwah πŸ’‹

πŸ“¦ where this page comes from