-
-
Save banker/1572678 to your computer and use it in GitHub Desktop.
MongoDB connection via C driver
This file contains 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]; | |
int 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_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