BSON_VALIDATE_FLAGS_T(3)

πŸ’… BSON_VALIDATE_FLAGS_T(3) β€” the libbson era, honestly iconic

πŸŽ€ Document validation options

okay bestie, gather round, because this page is literally the vibe check for your BSON documents and you're gonna slay it.


✨ SYNOPSIS ✨

#include <bson/bson-types.h>

typedef enum {
  BSON_VALIDATE_NONE = 0,
  BSON_VALIDATE_UTF8 = (1 << 0),
  BSON_VALIDATE_DOLLAR_KEYS = (1 << 1),
  BSON_VALIDATE_DOT_KEYS = (1 << 2),
  BSON_VALIDATE_UTF8_ALLOW_NULL = (1 << 3),
  BSON_VALIDATE_EMPTY_KEYS = (1 << 4),
  BSON_VALIDATE_CORRUPT = (1 << 5),
} bson_validate_flags_t;

🌸 DESCRIPTION 🌸

bson_validate_flags_t is a set of binary flags and you can combine them however you want to dial in exactly how much BSON document validation you're asking for. Mix and match, it's giving build-your-own-validation πŸ’…

A value of 0, false, or BSON_VALIDATE_NONE β€” all three, equivalently β€” requests the minimum applicable level of validation. Same energy, different spelling, no cap.

Now in the context of the validation APIs bson_validate(), bson_validate_with_error(), and bson_validate_with_error_and_offset(), that minimum validation still guarantees that a document can be successfully traversed by bson_iter_visit_all(). So even the bare minimum is doing real work, bestie 🫢

But heads up: higher level APIs using this type may have different minimum validation levels. For example, libmongoc functions that take bson_validate_flags_t use 0 to mean the document contents are not visited and malformed headers will not be detected by the client. So like, lowkey a whole different meaning over there πŸ‘€

Each defined flag aside from BSON_VALIDATE_NONE describes an optional validation feature that you can enable alone or in combination with other features:

  • BSON_VALIDATE_NONE β€” the minimum level of validation; in libbson, it validates element headers.
  • BSON_VALIDATE_UTF8 β€” all keys and string values get checked for invalid UTF-8. Very thorough, very demure ✨
  • BSON_VALIDATE_UTF8_ALLOW_NULL β€” string values are allowed to have embedded NULL bytes. Important: this does absolutely nothing unless BSON_VALIDATE_UTF8 is also passed. It's a package deal, iykyk πŸ”₯
  • BSON_VALIDATE_DOLLAR_KEYS β€” prohibits keys that start with $ outside of a "DBRef" subdocument. Not the dollar section, bestie πŸ’€
  • BSON_VALIDATE_DOT_KEYS β€” prohibits keys that contain . anywhere in the string. Anywhere. Periodt.
  • BSON_VALIDATE_EMPTY_KEYS β€” prohibits zero-length keys. No empty vibes allowed πŸ™ˆ
  • BSON_VALIDATE_CORRUPT β€” the plot twist: this one is not a control flag at all. It's used as an error code when a validation routine encounters corrupt BSON data.

πŸ¦‹ SEE ALSO:

bson_validate(), bson_validate_with_error(), bson_validate_with_error_and_offset().

bson_visitor_t can be used for custom validation β€” see Example Custom Validation. Main character energy for when the built-in flags aren't enough πŸ‘‘


🌈 AUTHOR 🌈

MongoDB, Inc


2009-present, MongoDB, Inc.


okay that's the whole page, you ate that πŸ“ and for the cute sign-off: this was libbson version 2.5.6, dated Oct 09, 2026 β€” bestie, go validate something iconic πŸ’œπŸ§š

πŸ“¦ where this page comes from