BSON_APPEND_CODE_WITH_SCOPE(3)
π BSON_APPEND_CODE_WITH_SCOPE(3) π
okay so bestie, welcome to libbson section 3 β this is the page for BSON_APPEND_CODE_WITH_SCOPE, and honestly? it's a little niche but it slaps. sit down, grab a strawberry drink π, and let's get into it.
β¨ SYNOPSIS β¨
the whole thing in code form, no cap:
#define BSON_APPEND_CODE_WITH_SCOPE(b, key, val, scope) \
bson_append_code_with_scope (b, key, (int) strlen (key), val, scope)
bool
bson_append_code_with_scope (bson_t *bson,
const char *key,
int key_length,
const char *javascript,
const bson_t *scope);
so yeah, there's a macro version that does the strlen() for you (iconic of her honestly) and the real function underneath doing all the actual work.
π PARAMETERS π
bsonβ abson_t. that's the document you're appending into, the main character of this whole situation πkeyβ an ASCII C string with the name of the field. just the label, bestie.key_lengthβ how longkeyis, in bytes. or you can pass-1and let it figure the length out withstrlen(). lowkey the lazy-girl option and we respect it πjavascriptβ aNULL-terminated UTF-8 encoded string holding the javascript fragment. yes, the actual code. UTF-8, don't play with me πscopeβ optionalbson_tcontaining the scope forjavascript. optional!! so you can skip it and nobody's mad π«Ά
π¦ DESCRIPTION π¦
okay so bson_append_code_with_scope() behaves just like bson_append_code() β same energy, same vibe β except it also lets you hand over a scope for the javascript function, and that scope comes in the form of a bson document. it's giving "code but make it have context" β¨
here's the tea on how it branches:
- if
scopeisNULL, it appends an element with BSON type"code" - otherwise, it appends an element with BSON type
"code with scope"
that's it, that's the whole personality. one little NULL check and the type flips. main character decision-making fr fr.
π₯ RETURNS π₯
returns true if the operation was applied successfully. slay β
but heads up bestie β the function will fail if appending javascript and scope grows bson larger than INT32_MAX. that's a real limit, not a drill π
π AUTHOR π
MongoDB, Inc β the icons themselves π
π COPYRIGHT π
2009-present, MongoDB, Inc.
and that's the page!! 2.5.6, Oct 09, 2026 β go forth and append your code-with-scope, bestie, you're gonna do amazing π§π
π¦ 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