- bson_record = wm_create_bson(ds, vl, node->store_rates);
- if (bson_record == NULL)
- return (ENOMEM);
+ INFO("write_mongodb plugin: Connecting to [%s]:%i",
+ (node->host != NULL) ? node->host : "localhost",
+ (node->port != 0) ? node->port : MONGOC_DEFAULT_PORT);
+
+ if ((node->db != NULL) && (node->user != NULL) && (node->passwd != NULL)) {
+ format_string = "mongodb://%s:%s@%s:%d/?authSource=%s";
+ uri_length = strlen(format_string) + strlen(node->user) +
+ strlen(node->passwd) + strlen(node->host) + 5 +
+ strlen(node->db) + 1;
+ if ((uri = calloc(sizeof(char), uri_length)) == NULL) {
+ ERROR("write_mongodb plugin: Not enough memory to assemble "
+ "authentication string.");
+ mongoc_client_destroy(node->client);
+ node->client = NULL;
+ node->connected = 0;
+ return -1;
+ }
+ ssnprintf(uri, uri_length, format_string, node->user, node->passwd,
+ node->host, node->port, node->db);