14

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?

DeSpider
  • 323
  • 2
  • 16
  • 5
    The error message indicates that your mLab deployment is using the older (and now deprecated) MMAPv1 storage engine which does not support document-level locking or transactions. Server-side multi-document transactions require a MongoDB 4.0+ replica set deployment using the WiredTiger storage engine. Upgrading your mLab deployment to meet the transaction requirements will resolve the error. – Stennie Apr 27 '19 at 09:04
  • did you solve it ? Thanks – CABascourt Jul 09 '19 at 02:04
  • 3
    Thanks to Stennie answer i was able to figure this out. I'm using Ruby/Rails with MongoID, and I was having the same issue (Transaction numbers are only allowed on storage engines that support document-level locking (20)), oddly it was only happening in the production environment (Heroku) and not in development environment, my mongoDB database was on mlab (3.6.12 (MMAPv1)) i moved to Atlas and the issue disappear + i'm running Mongo 4+ now. – Juan Ricardo Jul 17 '19 at 00:22
  • yes Carlos, just like Juan Ricardo I moved to mongodb cloud (atlas) and it was solved. – DeSpider Jul 18 '19 at 06:37
  • 1
    @JuanRicardo I had the same issue using Ruby/Rails I solved using mongo 2.8.0 driver. I was using mongoid 6.1.1 with mongo 2.9.0. Take a look at this [issue](https://jira.mongodb.org/browse/RUBY-1853) – Hernan Acosta Jul 24 '19 at 16:58
  • Note that databases hosted at mLab actually cannot be upgraded to version 4.0 or 4.2. However, you can migrate to MongoDB Atlas (MongoDB bought mLab) and get later versions thereafter. See this FAQ: https://docs.mlab.com/faq/#do-you-support-mongodb-40-or-42 – James Oct 21 '19 at 22:38

3 Answers3

15

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.

Kathy
  • 409
  • 4
  • 7
8

This worked for me by adding retryWrites=false ;

Current URL

 mongodb://<user>:<password>@ds0145508.mlab.com:11508/testdb

New URL

mongodb://<user>:<password>@ds0145508.mlab.com:11508/testdb?retryWrites=false 
Lijo
  • 6,498
  • 5
  • 49
  • 60
1

mlab.com runs mongodb 3.6, while the newest is 4.2.x and tools, db connectors, etc., want to use 4.x features.

In short, mlab.com is outdated.

Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120