Skip to content

Instantly share code, notes, and snippets.

@banker
Created August 22, 2011 19:54
Show Gist options
  • Save banker/1163348 to your computer and use it in GitHub Desktop.
Save banker/1163348 to your computer and use it in GitHub Desktop.
oplog.c
#include "mongo.h"
#include "bson.h"
int main() {
bson query[1], empty[1];
mongo conn[1];
int res;
mongo_cursor *cursor;
mongo_replset_init(conn, "test-rs");
mongo_replset_add_seed(conn, "127.0.0.1", 30000);
res = mongo_replset_connect(conn);
if(res != MONGO_OK) {
printf("Connect failed: %d", conn->err);
exit(1);
}
bson_init(query);
bson_append_bson(query, "$query", bson_empty(empty));
bson_append_start_object(query, "$orderby");
bson_append_int(query, "$natural", -1);
bson_append_finish_object(query);
bson_finish(query);
bson_print(query);
cursor = mongo_find(conn, "local.oplog.rs", query, bson_empty(empty), 0, 0, 0);
while (mongo_cursor_next(cursor) == MONGO_OK) {
bson_print( &cursor->current );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment