bson_iter_init_from_data(3)

bson_iter_init_from_data3

Usage

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

Parameters

•

iter: A bson_iter_t.

•

data: A buffer to initialize with.

•

length: The length of data in bytes.

Overview

The bson_iter_init_from_data() function shall initialize iter to iterate upon the buffer data, which must contain a BSON document. Upon initialization, iter is placed before the first element. Callers must call bson_iter_next(), bson_iter_find(), or bson_iter_find_case() to advance to an element.

Returns

Returns true if the iter was successfully initialized.

Examples

static void
print_doc_id (const uint8_t *data, size_t length)
{
   bson_iter_t iter;
   bson_oid_t oid;
   char oidstr[25];
   if (bson_iter_init_from_data (&iter, data, length) && bson_iter_find (&iter, "_id") &&
       BSON_ITER_HOLDS_OID (&iter)) {
      bson_iter_oid (&iter, &oid);
      bson_oid_to_string (&oid, oidstr);
      printf ("%s\n", oidstr);
   } else {
      printf ("Document is missing _id.\n");
   }
}

Releases

4 releases since Debian 10 (Buster); the text changed 3 times.

  1. 10
  2. 11
  3. 12
  4. 13

Author

MongoDB, Inc

From libbson-doc 1.30.4-1+deb13u3 in Debian 13 (Trixie). Parsed by carta from the page's man source.