简体   繁体   English

Mongodb atlas X509 auth 在事务中不起作用

[英]Mongodb atlas X509 auth doesn't work in transaction

I have a strange problem with Mongo Atlas using X509 certificate.我对使用 X509 证书的 Mongo Atlas 有一个奇怪的问题。 I have no problem connecting to Mongo Atlas usign X509 certificate, however, when I try to use it with a transaction I get the an error that the user is not authenticated.我连接到 Mongo Atlas usign X509 证书没有问题,但是,当我尝试将它与事务一起使用时,我收到用户未通过身份验证的错误。 This is my code:这是我的代码:

    const mongoOptions = {
        authSource: "$external",
        useNewUrlParser: true,
        useUnifiedTopology: true,
        sslCert: credentials,
        sslKey: credentials,
        authMechanism: "MONGODB-X509"
    };
    const mongo = new MongoClient(process.env.MONGO_URI, mongoOptions);
    const connection = await mongo.connect();
    const session = mongo.startSession();
    const db = mongo.db(`configs_${configPrefix}`, {});
    try {
        await session.startTransaction();
        await db.collection(collection).updateOne({_id: id}, {$set: jsonData}, {upsert: true, session});
        await session.commitTransaction();
    } catch (e) {
        await session.abortTransaction();
    } finally {
        await session.endSession();
        await connection.close();
    }

If I remove the session in the updateOne it works, if I add the session it throws the error.如果我在 updateOne 中删除 session 它可以工作,如果我添加 session 它会抛出错误。

If I'm using a username and password it works in all cases.如果我使用用户名和密码,它适用于所有情况。

Is there any limitation or steps that I am missing?我是否缺少任何限制或步骤?

Thanks谢谢

Enable command monitoring on the client, log all commands, observe that each command includes the connection id.在客户端启用命令监控,记录所有命令,观察每个命令都包含连接id。 Verify that the connections used for commands under transactions have previously authenticated.验证用于事务下的命令的连接先前是否已经过身份验证。

Enable query logging on the server and repeat the analysis on the server, verify each connection that does crud has previously authenticated.在服务器上启用查询日志记录并在服务器上重复分析,验证执行 crud 的每个连接先前已通过身份验证。

After some discussion and investigation with the atlas support.经过图集支持的一些讨论和调查。 They confirmed it's a bug in their shared clusters (M0, M2,M5).他们确认这是他们共享集群(M0、M2、M5)中的一个错误。 I can confirm that it's not happening in M10+.我可以确认它没有发生在 M10+ 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM