What is a TransientTransactionError in Mongoose (or MongoDB)?

前端 未结 16 1725
庸人自扰
庸人自扰 2020-11-27 07:36

I have server.js and db.js The db.js file interacts with my database using Mongoose and I use server.js to call functions

相关标签:
16条回答
  • 2020-11-27 08:04

    I had this problem when trying to connect my Heroku app to a MongoDB Atlas database.

    If you do a on you terminal

    heroku logs --tail

    You might see

    ERROR: { MongoNetworkError: 
    connection 4 to cluster0-shard-40-01-qnwp8.mongodb.net:27017 closed
    name: 'MongoNetworkError',
    errorLabels: [ 'TransientTransactionError' ],
    [Symbol(mongoErrorContextSymbol)]: {} }`
    

    After whitelisting the server connection on MongoDB Atlas, the database connection error was resolved.

    0 讨论(0)
  • 2020-11-27 08:06

    I had the same issue/error, albeit on a Windows machine. Even though I thought I had started the mongodb service, I didn't see it running in Windows Services. So, I manually started the mongoDB service inside Services and then the error went away. Hope this helps!

    0 讨论(0)
  • 2020-11-27 08:06

    I had similar problem... All day I was able to connect via mongoose. Then bang I started getting 'TransientTransactionError' error. I could connect to mongoDB via shell so I knew the server was up and running as expected.

    IPv6/localhost. My IP switched from IPv4 to IPv6. I resolved the issue by disabling IPv6 and getting regular IPv4 IP.

    EDIT -- seems I can reliably re/create this issue by connecting to 'localhost' while my NIC is configured with a IPv6 IP. Changing localhost->127.0.0.1 seems to resolve the issue.

    0 讨论(0)
  • 2020-11-27 08:09
    1. Go to your mongoDB Atlas Dashboard
    2. Open Network Access (its there in side navbar)
    3. Click on ADD IP ADDRESS
    4. Click on allow from Any IP Address ( it basically give access to your dynamic IP address)

    Now you are done.

    0 讨论(0)
  • 2020-11-27 08:10

    What is a TransientTransactionError

    A TransientTransactionError is a transactional error that is classified as temporary, and if retried it may be successful. Furthermore, a TransientTransactionError write conflict occurs prior to a commit when no write lock has been taken and the transaction (new data) is not reflected in the transaction snapshot (previous data.) As a result, these errors are completely safe to retry until there is a successful commit.

    Transactions that retry in this scenario are retried from the beginning of the transaction.

    Keep in mind This error label is different than commit errors that happen when the lock has been taken but the transaction can't complete its commit. The error label for this is UnknownTransactionCommitResult. The reference to this is notable due to the difference in understanding where in your application an error is occurring and what may be the underlying cause and how the application can and or will respond due to different error types.

    If you're using MongoDB supported drivers, there are two possible cause the code is getting this error:

    • Any database command error that includes the "TransientTransactionError" error label in the "errorLabels" field.
    • Any network error encountered running any command other than commitTransaction in a transaction.

    The code example in MongoDB Transactions: retry-transaction show cased how to handle TransientTransactionError.

    If the error message is MongoNetworkError, it means the transient transaction error is related to the network connectivity between the client and the server. This could either be a one time network glitch which is retry-able, or there is no network access which require network configuration. If the error is encountered on the first time the client trying to access the server, it is likely that there is network configuration needed. If the server is on MongoDB Atlas, please see Configure Whitelist Entries.

    0 讨论(0)
  • 2020-11-27 08:11

    If there is no security issue and you are just doing it for connecting: While setting up the IP Whitelist; format should be 0.0.0.0/0 , you will not face the issue.

    Moreover, as you have answered yourself, we can add the ip for which we need access.

    0 讨论(0)
提交回复
热议问题