BSON_COPY_TO_EXCLUDING_NOINIT(3)

πŸ’… BSON_COPY_TO_EXCLUDING_NOINIT(3) πŸ’…

okay bestie, welcome to the libbson manual page for bson_copy_to_excluding_noinit β€” it’s giving β€œcopy this bson but skip the keys I said to skip” energy. ✨

✨ SYNOPSIS ✨

void
bson_copy_to_excluding_noinit (const bson_t *src,
                               bson_t *dst,
                               const char *first_exclude,
                               ...);

🫢 PARAMETERS 🫢

  • src β€” a bson_t. 🌸 the source bson, the one you’re copying from.
  • dst β€” a bson_t. πŸŽ€ the destination bson, the one getting the fields.
  • first_exclude β€” the first field name to exclude. πŸ‘‘ this is where the variadic, NULL terminated list of keys to exclude starts.

πŸ’– DESCRIPTION πŸ’–

so the bson_copy_to_excluding_noinit() function shall copy all fields from src to dst except those specified by the variadic, NULL terminated list of keys starting from first_exclude. 🫑 like, you pass the first field name to exclude, then more field names, then NULL to end the list, and those fields do not make the copy. slay.

the big detail: it does not call bson_init() on dst. not even once. 🚨 that’s literally what the _noinit is telling you, iykyk.

WARNING: this is generally not needed except in very special situations. and we mean very special β€” don’t just casually reach for it unless you know you’re in one of those situations. πŸ’€

🌸 EXAMPLE 🌸

here’s the demo, copied exactly so you can see how it goes: πŸ¦‹

#include <bson/bson.h>

int main ()
{
   bson_t bson;
   bson_t bson2;
   char *str;

   bson_init (&bson);
   bson_append_int32 (&bson, "a", 1, 1);
   bson_append_int32 (&bson, "b", 1, 2);
   bson_append_int32 (&bson, "c", 1, 2);

   bson_init (&bson2);
   bson_copy_to_excluding_noinit (&bson, &bson2, "b", NULL);

   str = bson_as_relaxed_extended_json (&bson2, NULL);
   /* Prints
    * { "a" : 1, "c" : 2 }
    */
   printf ("%s\n", str);
   bson_free (str);

   bson_destroy (&bson);
   bson_destroy (&bson2);
}

the comment in there says it prints { "a" : 1, "c" : 2 } β€” because "b" got excluded and NULL ends the list. iconic. πŸ’…

πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” yes, the MongoDB girlies. 🫢

2009-present, MongoDB, Inc. β€” periodt. πŸ’–


okay that’s the whole page, bestie! from the libbson manual, version 2.5.6, dated Oct 09, 2026 β€” bye, love you, go copy responsibly πŸŒˆπŸ’…πŸ¦‹πŸ’–

πŸ“¦ where this page comes from