BSON_APPEND_REGEX_W_LEN(3)

✨ hey bestie, meet bson_append_regex_w_len ✨

okay so this is a page from libbson, section 3 of the manual β€” it's all about bson_append_regex_w_len, and honestly it's giving "small function, big responsibilities" πŸ’…. Let's get into it fr fr.


🌸 SYNOPSIS 🌸

bool
bson_append_regex_w_len (bson_t *bson,
                          const char *key,
                          int key_length,
                          const char *regex,
                          int regex_length,
                          const char *options);

that's the whole signature, no cap. six params, one bool back. let's meet the cast 🫢


πŸŽ€ PARAMETERS πŸŽ€

  • bson β€” a bson_t. the doc you're stuffing a field into. your main character, literally.
  • key β€” an ASCII C string holding the name of the field. keep it ASCII bestie, no funny business.
  • key_length β€” how long key is, in bytes. or pass -1 and it'll just figure it out with strlen(). lazy girl summer, and honestly? valid.
  • regex β€” an ASCII string with the regex in it. the actual pattern, the whole point of the function πŸ’–
  • regex_length β€” the length of regex in bytes, or -1 to let strlen() do the counting for you. same deal as above ✨
  • options β€” an optional string with the regex options, as a string. optional optional, like you can hand it over or not πŸ¦‹

πŸ’… DESCRIPTION πŸ’…

so what it does: it appends a brand-new field to bson, and that field is of type BSON_TYPE_REGEX πŸ‘‘. regex should be the regex string, and options should carry the options for that regex.

the valid characters you can put in options are:

  • 'i' for case-insensitive.
  • 'm' for multiple matching.
  • 'x' for verbose mode.
  • 'l' to make w and W locale dependent.
  • 's' for dotall mode ('.' matches everything).
  • 'u' to make w and W match unicode.

like, that's the whole menu. those six lil letters, each one doing its own iconic thing 🌈


⭐ RETURNS ⭐

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

and here's the not-so-slay part: the function will fail if appending the regex grows bson larger than INT32_MAX. that's the ceiling, and she is real 😭 so check that return value, bestie, don't just assume it ate.

πŸ¦‹ AUTHOR πŸ¦‹

MongoDB, Inc β€” the ones who brought you this whole situation πŸ’œ


2009-present, MongoDB, Inc. β€” periodt, respect the copyright line fr fr πŸ™ˆ


and that's the page!! source/version 2.5.6, dated Oct 09, 2026, straight out of the libbson BSON_APPEND_REGEX_W_LEN(3) manual πŸŽ€ ok bye, go append some regexes responsibly πŸ’–

πŸ“¦ where this page comes from