1BSON_ITER_INIT_FROM_DATA(3)         libbson        BSON_ITER_INIT_FROM_DATA(3)
2
3
4

SYNOPSIS

6          bool
7          bson_iter_init_from_data (bson_iter_t *iter, const uint8_t *data, size_t length);
8

PARAMETERS

10iter: A bson_iter_t.
11
12data: A buffer to initialize with.
13
14length: The length of data in bytes.
15

DESCRIPTION

17       The  bson_iter_init_from_data() function shall initialize iter to iter‐
18       ate upon the buffer data, which must contain a BSON document. Upon ini‐
19       tialization, iter is placed before the first element. Callers must call
20       bson_iter_next(), bson_iter_find(), or bson_iter_find_case() to advance
21       to an element.
22

RETURNS

24       Returns true if the iter was successfully initialized.
25

EXAMPLE

27          static void
28          print_doc_id (const uint8_t *data, size_t length)
29          {
30             bson_iter_t iter;
31             bson_oid_t oid;
32             char oidstr[25];
33
34             if (bson_iter_init_from_data (&iter, data, length) && 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

AUTHOR

45       MongoDB, Inc
46
48       2017-present, MongoDB, Inc
49
50
51
52
531.25.1                           Nov 08, 2023      BSON_ITER_INIT_FROM_DATA(3)
Impressum