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; inlibbson, 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 embeddedNULLbytes. Important: this does absolutely nothing unlessBSON_VALIDATE_UTF8is 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
π COPYRIGHT π
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
- 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