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