BSON_APPEND_ARRAY_UNSAFE_BEGIN(3)
π 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: Abson_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 ofkeyor-1to callstrlen(). yes you can just say-1and let it figure things out, we love a low-effort queen β¨child: Abson_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, seebson_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
π COPYRIGHT π
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
- epel 10: libbson-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