如何使用 MongoDB C 驱动程序和 FoundationDB 文档层进行交易?

How to do transactions using MongoDB C driver with FoundationDB Document Layer?

事务的 mongoc 文档使用会话。所以我试图在与会话关联的事务中插入文档。但是我得到了错误

[ 3666]:    ERROR:       mongoc: Failed to start session: Server does not support sessions

如何使用 MongoDB C 驱动程序和 FoundationDB 文档层进行交易?

我当前的代码是:

- (int)insertUser:(User *)user {
    mongoc_client_session_t *session;
    mongoc_session_opt_t *session_opts;
    mongoc_transaction_opt_t *default_txn_opts;
    mongoc_transaction_opt_t *txn_opts;
    mongoc_read_concern_t *read_concern;
    mongoc_write_concern_t *write_concern;
    bson_t *doc;
    bson_t *insert_opts;
    bson_error_t err;
    default_txn_opts = mongoc_transaction_opts_new();
    read_concern = mongoc_read_concern_new();
    mongoc_read_concern_set_level(read_concern, "snapshot");
    mongoc_transaction_opts_set_read_concern(default_txn_opts, read_concern);
    session_opts = mongoc_session_opts_new();
    mongoc_session_opts_set_default_transaction_opts(session_opts, default_txn_opts);
    session = mongoc_client_start_session(client, session_opts, &err);
    if (!session) {
        MONGOC_ERROR("Failed to start session: %s", err.message);
        return EXIT_FAILURE;
    }
    txn_opts = mongoc_transaction_opts_new();
    write_concern = mongoc_write_concern_new();
    mongoc_write_concern_set_wmajority(write_concern, 1000);  // write timeout
    mongoc_transaction_opts_set_write_concern(txn_opts, write_concern);
}
int insertUserTransaction(id param, mongoc_client_session_t *session, mongoc_transaction_opt_t *txn_opts, User *user, bson_error_t *err) {
    bool ret = mongoc_client_session_start_transaction(session, txn_opts, err);
    if (!ret) {
        MONGOC_ERROR("Failed to start transaction: %s", err->message);
        return EXIT_FAILURE;
    }
    // ...
}

文档层还不支持事务。它过去常常通过一些不同于 MongoDB 构造的构造来公开 FoundationDB 事务。但是他们被禁用了一段时间。