To construct a query in mongodb-c driver,
bson_init( query );
bson_finish( query );
// if you want to add more search parameters then in between those two add
bson_append_int( query, "age", 24 );
You can keep adding more search criteria.
Here is one example:
bson query[1];
mongo_cursor cursor[1];
bson_init( query );
bson_append_int( query_buf, "age", 24 ); // to match particular criteria, remove this line to match call documents
bson_finish( query );
mongo_cursor_init( cursor, conn, "test.collection" );
mongo_cursor_set_query( cursor, query )
while( mongo_cursor_next( cursor ) == MONGO_OK ) {
bson_iterator iterator[1];
if ( bson_find( iterator, mongo_cursor_bson( cursor ), "name" )) {
printf( "name: %s\n", bson_iterator_string( it ) );
}
}
bson_destroy( query );
mongo_cursor_destroy( cursor );
This is equivalent to:
db.collection.find()