- /* Assert if the connection has been established */
- assert (mongo_is_connected (node->conn));
-
- #if MONGO_MINOR >= 6
- /* There was an API change in 0.6.0 as linked below */
- /* https://github.com/mongodb/mongo-c-driver/blob/master/HISTORY.md */
- status = mongo_insert (node->conn, collection_name, bson_record, NULL);
- #else
- status = mongo_insert (node->conn, collection_name, bson_record);
- #endif
-
- if (status != MONGO_OK)
- {
- ERROR ( "write_mongodb plugin: error inserting record: %d", node->conn->err);
- if (node->conn->err != MONGO_BSON_INVALID)
- ERROR ("write_mongodb plugin: %s", node->conn->errstr);
- else
- ERROR ("write_mongodb plugin: Invalid BSON structure, error = %#x",
- (unsigned int) bson_record->err);
+ node->connected = 1;
+ return 0;
+} /* }}} int wm_initialize */
+
+static int wm_write(const data_set_t *ds, /* {{{ */
+ const value_list_t *vl, user_data_t *ud) {
+ wm_node_t *node = ud->data;
+ mongoc_collection_t *collection = NULL;
+ bson_t *bson_record;
+ bson_error_t error;
+ int status;
+
+ bson_record = wm_create_bson(ds, vl, node->store_rates);
+ if (!bson_record) {
+ ERROR("write_mongodb plugin: error making insert bson");
+ return -1;
+ }
+
+ pthread_mutex_lock(&node->lock);
+ if (wm_initialize(node) < 0) {
+ ERROR("write_mongodb plugin: error making connection to server");
+ pthread_mutex_unlock(&node->lock);
+ bson_free(bson_record);
+ return -1;
+ }