1BSON_VALIDATE_WITH_ERROR(3) libbson BSON_VALIDATE_WITH_ERROR(3)
2
3
4
6 typedef enum {
7 BSON_VALIDATE_NONE = 0,
8 BSON_VALIDATE_UTF8 = (1 << 0),
9 BSON_VALIDATE_DOLLAR_KEYS = (1 << 1),
10 BSON_VALIDATE_DOT_KEYS = (1 << 2),
11 BSON_VALIDATE_UTF8_ALLOW_NULL = (1 << 3),
12 BSON_VALIDATE_EMPTY_KEYS = (1 << 4),
13 } bson_validate_flags_t;
14
15 bool
16 bson_validate_with_error (const bson_t *bson,
17 bson_validate_flags_t flags,
18 bson_error_t *error);
19
21 • bson: A bson_t.
22
23 • flags: A bitwise-or of all desired validation flags.
24
25 • error: Optional bson_error_t.
26
28 Validates a BSON document by walking through the document and inspect‐
29 ing the keys and values for valid content.
30
31 You can modify how the validation occurs through the use of the flags
32 parameter. A description of their effect is below.
33
34 • BSON_VALIDATE_NONE Basic validation of BSON length and structure.
35
36 • BSON_VALIDATE_UTF8 All keys and string values are checked for invalid
37 UTF-8.
38
39 • BSON_VALIDATE_UTF8_ALLOW_NULL String values are allowed to have em‐
40 bedded NULL bytes.
41
42 • BSON_VALIDATE_DOLLAR_KEYS Prohibit keys that start with $ outside of
43 a "DBRef" subdocument.
44
45 • BSON_VALIDATE_DOT_KEYS Prohibit keys that contain . anywhere in the
46 string.
47
48 • BSON_VALIDATE_EMPTY_KEYS Prohibit zero-length keys.
49
51 Returns true if bson is valid; otherwise false and error is filled out.
52
53 The bson_error_t domain is set to BSON_ERROR_INVALID. Its code is set
54 to one of the bson_validate_flags_t flags indicating which validation
55 failed; for example, if a key contains invalid UTF-8, then the code is
56 set to BSON_VALIDATE_UTF8, but if the basic structure of the BSON docu‐
57 ment is corrupt, the code is set to BSON_VALIDATE_NONE. The error mes‐
58 sage is filled out, and gives more detail if possible.
59
60 SEE ALSO:
61 bson_validate().
62
63 bson_visitor_t can be used for custom validation, Example Custom Validation.
64
65
67 MongoDB, Inc
68
70 2017-present, MongoDB, Inc
71
72
73
74
751.25.1 Nov 08, 2023 BSON_VALIDATE_WITH_ERROR(3)