Created
January 6, 2012 22:09
-
-
Save anonymous/1572630 to your computer and use it in GitHub Desktop.
MongoDB connection via C driver
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
#include <stdio.h> | |
#include "mongo.h" | |
int main() { | |
mongo conn[1]; | |
status = mongo_connect( conn, "127.0.0.1", 27017 ); | |
if( status != MONGO_OK ) { | |
switch ( conn->err ) { | |
case MONGO_CONN_SUCCESS: printf( "connection succeeded\n" ); break; | |
case MONGO_CONN_BAD_ARG: printf( "bad arguments\n" ); return 1; | |
case MONGO_CONN_NO_SOCKET: printf( "no socket\n" ); return 1; | |
case MONGO_CONN_FAIL: printf( "connection failed\n" ); return 1; | |
case MONGO_CONN_NOT_MASTER: printf( "not master\n" ); return 1; | |
} | |
} | |
mongo_destroy( conn ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment