#include <mongoc/mongoc.h>
int main (int argc, char *argv[])
{
mongoc_client_t *client;
mongoc_database_t *database;
mongoc_collection_t *collection;
mongoc_cursor_t *cursor;
bson_t query;
const bson_t *doc;
bson_iter_t iter;
mongoc_init ();
client = mongoc_client_new ("mongodb://localhost:27017/");
database = mongoc_client_get_database (client, "your_database_name");
collection = mongoc_client_get_collection (client, "your_database_name", "your_collection_name");
BSON_APPEND_INT32 (&query, "your_field_name", BSON_INT32 (your_target_value));
cursor = mongoc_collection_find_with_opts (collection, &query, NULL, NULL);
while (mongoc_cursor_next (cursor, &doc)) {
if (bson_iter_init_find (&iter, doc, "your_field_name") && BSON_ITER_HOLDS_INT32 (&iter)) {
int32_t value = bson_iter_int32 (&iter);
printf ("%d\n", value);
}
}
bson_destroy (&query);
mongoc_cursor_destroy (cursor);
mongoc_collection_destroy (collection);
mongoc_database_destroy (database);
mongoc_client_destroy (client);
mongoc_cleanup ();
return 0;
}