bson_iter_t (3) - Linux Manuals
bson_iter_t: BSON Document Iterator
Command to display bson_iter_t
manual in Linux: $ man 3 bson_iter_t
NAME
bson_iter_t - BSON Document Iterator
SYNOPSIS
#include <bson.h>
typedef struct
{
/*< private >*/
} bson_iter_t;
DESCRIPTION
bson_iter_t
is a structure used to iterate through the elements of a
bson_t
\&. It is meant to be used on the stack and can be discarded at any time as it contains no external allocation. The contents of the structure should be considered private and may change between releases, however the structure size will not change.
The
bson_t
MUST
be valid for the lifetime of the iter and it is an error to modify the
bson_t
while using the iter.
EXAMPLES
bson_iter_t iter;
if (bson_iter_init (&iter, my_bson_doc)) {
while (bson_iter_next (&iter)) {
printf ("Found a field named: %s\n", bson_iter_key (&iter));
}
}
bson_iter_t iter;
if (bson_iter_init (&iter, my_bson_doc) &&
bson_iter_find (&iter, "my_field")) {
printf ("Found the field named: %s\n", bson_iter_key (&iter));
}
bson_iter_t iter;
bson_iter_t sub_iter;
if (bson_iter_init_find (&iter, my_bson_doc, "mysubdoc") &&
(BSON_ITER_HOLDS_DOCUMENT (&iter) ||
BSON_ITER_HOLDS_ARRAY (&iter)) &&
bson_iter_recurse (&iter, &sub_iter)) {
while (bson_iter_next (&sub_iter)) {
printf ("Found key \"%s\" in sub document.\n",
bson_iter_key (&sub_iter));
}
}
bson_iter_t iter;
if (bson_iter_init (&iter, my_doc) &&
bson_iter_find_descendant (&iter, "a.b.c.d", &sub_iter)) {
printf ("The type of a.b.c.d is: %d\n",
(int)bson_iter_type (&sub_iter));
}
COLOPHON
This page is part of libbson.
Please report any bugs at
https://jira.mongodb.org/browse/CDRIVER.
Pages related to bson_iter_t
- bson_iter_time_t (3) - The bson_iter_time_t() function shall return the number of seconds since the UNIX epoch, as contained in the BSON_TYPE_DATE_TIME element.
- bson_iter_timestamp (3) - The BSON_TYPE_TIMESTAMP type is not a date/time and is typically used for intra-server communication.
- bson_iter_timeval (3) - The bson_iter_timeval() function shall return the number of seconds and microseconds since the UNIX epoch, as contained in the BSON_TYPE_DATE_TIME element into tv.
- bson_iter_type (3) - The bson_iter_type() function shall return the type of the observed element in a bson document.
- bson_iter_array (3) - The bson_iter_array() function shall retrieve the raw buffer of a sub-array from iter. iter MUST be on an element that is of type BSON_TYPE_ARRAY. This can be verified with bson_iter_type() or the BSON_ITER_HOLDS_ARRAY() macro.
- bson_iter_as_bool (3) - Fetches the current field as if it were a boolean.
- bson_iter_as_int64 (3) - The bson_iter_as_int64() function shall return the contents of the current element as if it were a BSON_TYPE_INT64 element. The currently supported casts include:
- bson_iter_binary (3) - This function shall return the binary data of a BSON_TYPE_BINARY element. It is a programming error to call this function on a field that is not of type BSON_TYPE_BINARY. You can check this with the BSON_ITER_HOLDS_BINARY() macro or bson_iter_type().
- bson_iter_bool (3) - The bson_iter_bool()function shall return the boolean value of a BSON_TYPE_BOOL element. It is a programming error to call this function on an element other than BSON_TYPE_BOOL. You can check this with bson_iter_type() or BSON_ITER_HOLDS_BOOL().
- bson_iter_code (3) - This function returns the contents of a BSON_TYPE_CODE field. The length of the string is stored in length if non-NULL.
- bson_iter_codewscope (3) - The bson_iter_codewscope() function acts similar to bson_iter_code() except for BSON_TYPE_CODEWSCOPE elements. It also will provide a pointer to the buffer for scope, which can be loaded into a bson_t using bson_init_static().
- bson_iter_date_time (3) - The bson_iter_date_time() function shall return the number of miliseconds since the UNIX epoch, as contained in the BSON_TYPE_DATE_TIME element.
- bson_iter_dbpointer (3) - Fetches the contents of a BSON_TYPE_DBPOINTER element.
- bson_iter_document (3) - The bson_iter_document() function shall retrieve the raw buffer of a sub-document from iter. iter MUST be on an element that is of type BSON_TYPE_DOCUMENT. This can be verified with bson_iter_type() or the BSON_ITER_HOLDS_DOCUMENT() macro.