1BSON_ITER_T(3)                      libbson                     BSON_ITER_T(3)
2
3
4
5BSON Document Iterator
6

SYNOPSIS

8          #include <bson/bson.h>
9
10          #define BSON_ITER_HOLDS_DOUBLE(iter) /* ... */
11
12          #define BSON_ITER_HOLDS_UTF8(iter) /* ... */
13
14          #define BSON_ITER_HOLDS_DOCUMENT(iter) /* ... */
15
16          #define BSON_ITER_HOLDS_ARRAY(iter) /* ... */
17
18          #define BSON_ITER_HOLDS_BINARY(iter) /* ... */
19
20          #define BSON_ITER_HOLDS_UNDEFINED(iter) /* ... */
21
22          #define BSON_ITER_HOLDS_OID(iter) /* ... */
23
24          #define BSON_ITER_HOLDS_BOOL(iter) /* ... */
25
26          #define BSON_ITER_HOLDS_DATE_TIME(iter) /* ... */
27
28          #define BSON_ITER_HOLDS_NULL(iter) /* ... */
29
30          #define BSON_ITER_HOLDS_REGEX(iter) /* ... */
31
32          #define BSON_ITER_HOLDS_DBPOINTER(iter) /* ... */
33
34          #define BSON_ITER_HOLDS_CODE(iter) /* ... */
35
36          #define BSON_ITER_HOLDS_SYMBOL(iter) /* ... */
37
38          #define BSON_ITER_HOLDS_CODEWSCOPE(iter) /* ... */
39
40          #define BSON_ITER_HOLDS_INT32(iter) /* ... */
41
42          #define BSON_ITER_HOLDS_TIMESTAMP(iter) /* ... */
43
44          #define BSON_ITER_HOLDS_INT64(iter) /* ... */
45
46          #define BSON_ITER_HOLDS_DECIMAL128(iter) /* ... */
47
48          #define BSON_ITER_HOLDS_MAXKEY(iter) /* ... */
49
50          #define BSON_ITER_HOLDS_MINKEY(iter) /* ... */
51
52          #define BSON_ITER_HOLDS_INT(iter) \
53             (BSON_ITER_HOLDS_INT32 (iter) || BSON_ITER_HOLDS_INT64 (iter))
54
55          #define BSON_ITER_HOLDS_NUMBER(iter) \
56             (BSON_ITER_HOLDS_INT (iter) || BSON_ITER_HOLDS_DOUBLE (iter))
57
58          #define BSON_ITER_IS_KEY(iter, key) \
59             (0 == strcmp ((key), bson_iter_key ((iter))))
60
61          typedef struct {
62             /*< private >*/
63          } bson_iter_t;
64

DESCRIPTION

66       bson_iter_t  is  a  structure used to iterate through the elements of a
67       bson_t. It is meant to be used on the stack and can be discarded at any
68       time  as it contains no external allocation. The contents of the struc‐
69       ture should be considered private and may change between releases, how‐
70       ever the structure size will not change.
71
72       The  bson_t MUST be valid for the lifetime of the iter and it is an er‐
73       ror to modify the bson_t while using the iter.
74

EXAMPLES

76          bson_iter_t iter;
77
78          if (bson_iter_init (&iter, my_bson_doc)) {
79             while (bson_iter_next (&iter)) {
80                printf ("Found a field named: %s\n", bson_iter_key (&iter));
81             }
82          }
83
84          bson_iter_t iter;
85
86          if (bson_iter_init (&iter, my_bson_doc) && bson_iter_find (&iter, "my_field")) {
87             printf ("Found the field named: %s\n", bson_iter_key (&iter));
88          }
89
90          bson_iter_t iter;
91          bson_iter_t sub_iter;
92
93          if (bson_iter_init_find (&iter, my_bson_doc, "mysubdoc") &&
94              (BSON_ITER_HOLDS_DOCUMENT (&iter) || BSON_ITER_HOLDS_ARRAY (&iter)) &&
95              bson_iter_recurse (&iter, &sub_iter)) {
96             while (bson_iter_next (&sub_iter)) {
97                printf ("Found key \"%s\" in sub document.\n", bson_iter_key (&sub_iter));
98             }
99          }
100
101          bson_iter_t iter;
102
103          if (bson_iter_init (&iter, my_doc) &&
104              bson_iter_find_descendant (&iter, "a.b.c.d", &sub_iter)) {
105             printf ("The type of a.b.c.d is: %d\n", (int) bson_iter_type (&sub_iter));
106          }
107

AUTHOR

109       MongoDB, Inc
110
112       2017-present, MongoDB, Inc
113
114
115
116
1171.25.1                           Nov 08, 2023                   BSON_ITER_T(3)
Impressum