I'm trying to persit my mongoDB connection like that :
mongo **ptr = (mongo**)get_env(argv, US_VHOST_DATA);
if(!ptr[0]) {
mongo_replica_set_init( conn, "cluster" );
mongo_replica_set_add_seed( conn, "mongo1.mongood.com", 27017 );
mongo_replica_set_add_seed( conn, "mongo3.mongood.com", 27017 );
mongo_replica_set_add_seed( conn, "mongo4.mongood.com", 27017 );
mongo_replica_set_add_seed( conn, "mongo5.mongood.com", 27017 );
mongo_replica_set_add_seed( conn, "mongo6.mongood.com", 27017 );
mongo_replica_set_client( conn );
mongo_cmd_authenticate( conn, "dbname", "dbuser", "dbpass" );
ptr[0] = (mongo*)calloc(1, sizeof(conn));
} else {
conn[0] = *ptr[0];
}
int count = 0;
count = mongo_count( ptr[0], "dbname", "coll", NULL);
mongo_destroy( ptr[0] );
xbuf_xcat(reply, "<h3>%d</h3>", count);
But obviously, it don't work... My goal is to avoid connection time on each request (~30ms)
It is doable ? What is wrong in this example ?
The code don't complain but it just return -1 instead of the right count number.
Thank you for your help.
[EDIT] Removing the else block and removing the mongo_destroy line just work as expected \o/