NEOERR* mmg_string_update(mmg_conn *db, char *dsn, int flags, char *up, char *sel) { bson *doca, *docb; MCS_NOT_NULLC(db, dsn, up); mtc_noise("update %s %s %s", dsn, up, sel); if (sel) { doca = mbson_new_from_string(sel, true); if (!doca) return nerr_raise(NERR_ASSERT, "build doc sel: %s: %s", sel, strerror(errno)); } else doca = NULL; docb = mbson_new_from_string(up, true); if (!docb) return nerr_raise(NERR_ASSERT, "build doc up: %s: %s", up, strerror(errno)); if (!mongo_sync_cmd_update(db->con, dsn, flags, doca, docb)) return nerr_raise(NERR_DB, "sync_cmd_update: %s", strerror(errno)); bson_free(doca); bson_free(docb); return STATUS_OK; }
static gboolean afmongodb_worker_insert (MongoDBDestDriver *self) { gboolean success; guint8 *oid; LogMessage *msg; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; afmongodb_dd_connect(self, TRUE); g_mutex_lock(self->queue_mutex); log_queue_reset_parallel_push(self->queue); success = log_queue_pop_head(self->queue, &msg, &path_options, FALSE, FALSE); g_mutex_unlock(self->queue_mutex); if (!success) return TRUE; msg_set_context(msg); bson_reset (self->bson_sel); bson_reset (self->bson_upd); bson_reset (self->bson_set); oid = mongo_util_oid_new_with_time (self->last_msg_stamp, self->seq_num); bson_append_oid (self->bson_sel, "_id", oid); g_free (oid); bson_finish (self->bson_sel); value_pairs_foreach (self->vp, afmongodb_vp_foreach, msg, self->seq_num, self->bson_set); bson_finish (self->bson_set); bson_append_document (self->bson_upd, "$set", self->bson_set); bson_finish (self->bson_upd); if (!mongo_sync_cmd_update (self->conn, self->ns, MONGO_WIRE_FLAG_UPDATE_UPSERT, self->bson_sel, self->bson_upd)) { msg_error ("Network error while inserting into MongoDB", evt_tag_int("time_reopen", self->time_reopen), NULL); success = FALSE; } msg_set_context(NULL); if (success) { stats_counter_inc(self->stored_messages); step_sequence_number(&self->seq_num); log_msg_ack(msg, &path_options); log_msg_unref(msg); } else { g_mutex_lock(self->queue_mutex); log_queue_push_head(self->queue, msg, &path_options); g_mutex_unlock(self->queue_mutex); } return success; }