BSON_APPEND_ARRAY_UNSAFE_BEGIN(3)

πŸ“¦
version 2.5.6 Β· 2 versions
, in epel 10

πŸ’… BSON_APPEND_ARRAY_UNSAFE_BEGIN(3) πŸ’…

okay so bestie, you've wandered into the libbson section 3 manual, and this page is all about bson_append_array_unsafe_begin β€” yes the name is a lot, no we are not scared of it. it's giving "long function name, big personality" energy fr fr πŸŽ€


✨ SYNOPSIS ✨

the macro version, so you can be lazy about key lengths (iconic behaviour honestly):

#define BSON_APPEND_ARRAY_UNSAFE_BEGIN(b, key, child) \
   bson_append_array_unsafe_begin (b, key, (int) strlen (key), child)

and the actual function underneath, in all its glory:

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

🌸 PARAMETERS 🌸

  • bson: A bson_t. your main character document, the one we're appending into πŸ’–
  • key: A string containing the name for the key. as in, what you're calling this array.
  • key_length: The length of key or -1 to call strlen(). yes you can just say -1 and let it figure things out, we love a low-effort queen ✨
  • child: A bson_t. this is the sub-array you're building, your little side quest πŸ¦‹

πŸ’œ DESCRIPTION πŸ’œ

okay so bson_append_array_unsafe_begin() shall begin appending an array field to bson. it lets you build a sub-array incrementally β€” like, piece by piece, no big dramatic finale needed. and the way it does it is genuinely the serve: it generally yields better performance because you serialize to a single buffer instead of bouncing around 😭πŸ”₯

when you're done building the sub-array, the caller MUST call bson_append_array_end(). like, MUST must. not optional, not "later bestie", just do it 🫢

heads up: the caller is responsible for generating the array element keys correctly β€” "0", "1", "2", ... and so on. that's on you, not the library. for generating those keys, see bson_uint32_to_string() πŸ’…

ngl, if you don't feel like hand-generating array element keys at all, consider using bson_array_builder_t to append an array without needing to generate them. skipped the whole homework assignment, ate πŸ’€


⭐ RETURNS ⭐

Returns true if the operation was applied successfully. πŸŽ‰

the function will fail if appending the array grows bson larger than INT32_MAX. that's the ceiling, that's the limit, and no cap we cannot go past it 😀

🌈 SEE ALSO: 🌈

  • bson_array_builder_t

πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc

2009-present, MongoDB, Inc.


and that's the whole page, bestie β€” no crumbs left behind πŸ§šπŸ’–

libbson version 2.5.6, dated Oct 09, 2026. mwah, go build some arrays responsibly πŸ’…βœ¨πŸ“

πŸ“¦ where this page comes from