BSON_VALIDATE(3)
π BSON_VALIDATE(3) β the libbson one, bestie
okay so like, this is the bson_validate page from libbson, and it's genuinely one of the most useful little functions ever. no cap. let's get into it π«Ά
β¨ SYNOPSIS β¨
bool
bson_validate (const bson_t *bson, bson_validate_flags_t flags, size_t *offset);
like, that's the whole vibe. three args, one bool back. iconic.
π PARAMETERS π
bsonβ abson_t. the document you're side-eyeing. πflagsβ a bitwise-or of all thebson_validate_flags_tyou want. yes, all of them, or just some, you do you.offsetβ optional spot where the error offset gets written. optional optional. you can literally pass nothing here and it's fine.
π DESCRIPTION π
so what it does is validate a BSON document β it literally walks through the whole thing, inspecting the keys and the values, checking that the content is valid. like a little vibe check for your bytes. πΈ
and you can change up how the validation happens using the flags parameter β go look at bson_validate_flags_t for the deets, iykyk.
π RETURNS π
if bson passes the validations you asked for, it returns true. slay. π
otherwise it returns false, and β if offset is non-NULL β that pointer gets written with the byte offset in the document where the error was detected. so you know exactly where it went wrong. very main character of it.
π¨ heads up bestie: if you want more info about the specific validation failure, use bson_validate_with_error_and_offset() instead. this one's just giving you the offset, not the whole story. π
π¦ SEE ALSO
bson_validate_with_error()bson_validate_with_error_and_offset()
also! bson_visitor_t can be used for custom validation β see Example Custom Validation. for when you wanna do it your own way, periodt. π₯
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
and that's the page!! β¨ version 2.5.6, dated Oct 09, 2026 β mwah, go validate some BSON, bestie ππ¦
π¦ 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