Created
December 8, 2010 16:35
-
-
Save banker/733512 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To compile from the root of the c driver | |
scons | |
gcc -static -std=c99 -Wall query.c -I./src -L. -lbson -lmongoc -o query |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* query.c */ | |
#include "bson.h" | |
#include "mongo.h" | |
int main() { | |
bson b; | |
bson_buffer bb; | |
bson_buffer_init( &bb ); | |
{ | |
bson_buffer * query = bson_append_start_object( &bb, "$query"); | |
bson_buffer * spec = bson_append_start_object( &bb, "foo"); | |
bson_append_int( spec, "$gt", 1); | |
bson_append_finish_object( spec ); | |
bson_append_finish_object( query ); | |
} | |
{ | |
bson_buffer * sort = bson_append_start_object( &bb, "$sort"); | |
bson_append_int( sort, "foo", -1); | |
bson_append_finish_object( sort ); | |
} | |
bson_append_finish_object( &bb ); | |
bson_from_buffer( &b , &bb ); | |
bson_print( &b ); | |
const char * ns = "test.things"; | |
mongo_connection conn[1]; | |
mongo_connect( conn , NULL ); | |
mongo_cursor * cursor; | |
cursor = mongo_find( conn , ns , &b , 0 , 0 , 0 , 0 ); | |
while (mongo_cursor_next(cursor)){ | |
bson_iterator it; | |
bson_iterator_init(&it, cursor->current.data); | |
bson_print(&(cursor->current)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment