1BSON_ITER_T(3)                      libbson                     BSON_ITER_T(3)
2
3
4

NAME

6       bson_iter_t - bson_iter_t
7
8       BSON Document Iterator
9

SYNOPSIS

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

DESCRIPTION

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

EXAMPLES

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

AUTHOR

112       MongoDB, Inc
113
115       2017-present, MongoDB, Inc
116
117
118
119
1201.23.1                           Oct 20, 2022                   BSON_ITER_T(3)
Impressum