1BSON_ITER_INIT(3)                   libbson                  BSON_ITER_INIT(3)
2
3
4

NAME

6       bson_iter_init - bson_iter_init()
7

SYNOPSIS

9          bool
10          bson_iter_init (bson_iter_t *iter, const bson_t *bson);
11

PARAMETERS

13       · iter: A bson_iter_t.
14
15       · bson: A bson_t.
16

DESCRIPTION

18       The bson_iter_init() function shall initialize iter to iterate upon the
19       BSON document bson. Upon initialization,  iter  is  placed  before  the
20       first element. Callers must call bson_iter_next(), bson_iter_find(), or
21       bson_iter_find_case() to advance to an element.
22

RETURNS

24       Returns true if the iter was successfully initialized.
25

EXAMPLE

27          static void
28          print_doc_id (const bson_t *doc)
29          {
30             bson_iter_t iter;
31             bson_oid_t oid;
32             char oidstr[25];
33
34             if (bson_iter_init (&iter, doc) && bson_iter_find (&iter, "_id") &&
35                 BSON_ITER_HOLDS_OID (&iter)) {
36                bson_iter_oid (&iter, &oid);
37                bson_oid_to_string (&oid, oidstr);
38                printf ("%s\n", oidstr);
39             } else {
40                printf ("Document is missing _id.\n");
41             }
42          }
43
44          /* alternatively */
45
46          static void
47          print_doc_id (const bson_t *doc)
48          {
49             bson_iter_t iter;
50             bson_oid_t oid;
51             char oidstr[25];
52
53             if (bson_iter_init_find (&iter, doc, "_id") && BSON_ITER_HOLDS_OID (&iter)) {
54                bson_iter_oid (&iter, &oid);
55                bson_oid_to_string (&oid, oidstr);
56                printf ("%s\n", oidstr);
57             } else {
58                printf ("Document is missing _id.\n");
59             }
60          }
61

AUTHOR

63       MongoDB, Inc
64
66       2017-present, MongoDB, Inc
67
68
69
70
711.16.2                           Feb 25, 2020                BSON_ITER_INIT(3)
Impressum