Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to solve this transaction error in mlab? [MongoError: Transaction numbers are ... support document-level locking]

I'm trying to do a simple transaction using mongoose. It worked totally fine on MongoDB Atlas, but in mlab I got such an error: MongoError: Transaction numbers are only allowed on storage engines that support document-level locking. I did some research, but didn't really find any resources regarding mlab and document-level locking. Does anyone know how to solve this problem?

like image 468
DeSpider Avatar asked Apr 27 '19 07:04

DeSpider


People also ask

How can you achieve transaction and locking in MongoDB?

User 1 -> read request start User 2 -> read request start User 1 -> read request success (booking available) User 2 -> read request success (booking available) User 1 -> write a new record to the db (new booking) User 2 -> write a new record to the db (new booking) but this conflicts with User 1.

What is MongoDB transaction?

For situations that require atomicity of reads and writes to multiple documents (in a single or multiple collections), MongoDB supports multi-document transactions. With distributed transactions, transactions can be used across multiple operations, collections, databases, documents, and shards.


1 Answers

I have same issue, then I contact mlab help, here is their reply:

That error indicates your app/driver is attempting to use a feature that's not compatible with your Shared Cluster deployment, which employs the MMAPv1 storage einge. It's likely that you have retryable writes (https://docs.mongodb.com/manual/core/retryable-writes/) enabled. Can you try turning that feature off in the connection string (https://docs.mongodb.com/manual/reference/connection-string/#urioption.retryWrites), or directly from your driver settings?

Please let us know if you continue to experience this error after turning off this feature.

Based on this answer, I appended retryWrites=false in mongodb connection url, then it works well.

like image 159
Kathy Avatar answered Sep 21 '22 04:09

Kathy