#include <mongoc.h>#include <pthread.h>//set scheduler-locking on#define N_THREADS 10static void *worker(void *data){mongoc_client_pool_t *pool = data;mongoc_client_t *client;mongoc_collection_t *collection;bson_error_t error;bson_oid_t oid;bson_t *doc;mongoc_init ();client = mongoc_client_pool_pop(pool);collection = mongoc_client_get_collection (client, "mydb", "mycoll");doc = bson_new ();bson_oid_init (&oid, NULL);BSON_APPEND_OID (doc, "_id", &oid);BSON_APPEND_UTF8 (doc, "hello", "world");if (!mongoc_collection_insert (collection, MONGOC_INSERT_NONE, doc, NULL, &error)) {fprintf (stderr, "%s\n", error.message);}bson_destroy (doc);mongoc_collection_destroy (collection);mongoc_cleanup ();mongoc_client_pool_push(pool, client);return NULL;}int main(int argc, char *argv[]){mongoc_client_pool_t *pool;mongoc_uri_t *uri;pthread_t threads[N_THREADS];mongoc_init();uri = mongoc_uri_new("mongodb://localhost/");pool = mongoc_client_pool_new(uri);int i;for (i = 0; i < N_THREADS; i++){pthread_create(&threads[i], NULL, worker, pool);}for (i = 0; i < N_THREADS; i++){pthread_join(threads[i], NULL);}mongoc_client_pool_destroy(pool);mongoc_uri_destroy(uri);mongoc_cleanup();return 0;}
uri = mongoc_uri_new("mongodb://localhost/");
uri = mongoc_uri_new ("mongodb://localhost/?serverSelectionTimeoutMS=999999");
if (!mongoc_collection_insert (collection, MONGOC_INSERT_NONE, doc, NULL, &error)) {fprintf (stderr, "%s\n", error.message);}
No suitable servers found: `serverSelectionTimeoutMS` expired
#include <mongoc.h>#include <pthread.h>//set scheduler-locking on#define N_THREADS 10static void *worker(void *data){mongoc_client_pool_t *pool = data;mongoc_client_t *client;mongoc_collection_t *collection;bson_error_t error;bson_oid_t oid;bson_t *doc;
client = mongoc_client_pool_pop(pool);collection = mongoc_client_get_collection (client, "mydb", "mycoll");doc = bson_new ();bson_oid_init (&oid, NULL);BSON_APPEND_OID (doc, "_id", &oid);BSON_APPEND_UTF8 (doc, "hello", "world");if (!mongoc_collection_insert (collection, MONGOC_INSERT_NONE, doc, NULL, &error)) {fprintf (stderr, "%s\n", error.message);}bson_destroy (doc);mongoc_collection_destroy (collection);
mongoc_client_pool_push(pool, client);return NULL;}int main(int argc, char *argv[]){mongoc_client_pool_t *pool;mongoc_uri_t *uri;pthread_t threads[N_THREADS];mongoc_init();
uri = mongoc_uri_new ("mongodb://localhost/?serverSelectionTimeoutMS=999999");
pool = mongoc_client_pool_new(uri);int i;for (i = 0; i < N_THREADS; i++){pthread_create(&threads[i], NULL, worker, pool);}for (i = 0; i < N_THREADS; i++){pthread_join(threads[i], NULL);}mongoc_client_pool_destroy(pool);mongoc_uri_destroy(uri);mongoc_cleanup();return 0;}
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1053c3f9-f426-41fa-b0ab-c3b4a99e688e%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/Dss4mFP_T68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.