4

My team has encountered a problem while moving from regular MongoDB server to AWS DocumentDB.

Basically DocumentDB does not support cursors in transactions which is kinda a problem for us.

It results in exception when finding more than 102 documents from collection within transaction. I don't know why it's exactly 102 but it happens to be number of documents which causes an issue for me, anything less than that works just fine, and anything more than that results in

org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 303 and error message 'Feature not supported: cursor within transaction. Try increasing the batchsize.'

Any idea how to resolve this issue? The first thing that came to my mind was not finding documents within transactions but I'd rather leave it as the last option.

Here are the files where you can reproduce it:

MongoTransactionApplication.java

application.yaml

pom.xml

edit: forgot to mention this initially but Mongo and DocumentDB servers are both version 4.0

SirKometa
  • 1,857
  • 3
  • 16
  • 26
  • 1
    i'm not familiar with spring or aws document db, but looking at the error message you also may try to increase `batchSize` that should increase a magic `102` value. – dododo Jul 20 '21 at 10:42

1 Answers1

1

Since this is an unsupported feature, I guess one solution could be to re-structure your code (if possible), so that the findAll operations is done before the transaction starts.

If this is unfeasible, the batch size can be increased using e.g. the @Meta(cursorBatchSize = 1000) annotation on your query methods in your repository interface.

If you are doing programmatic queries you can also set it when building a query using the org.springframework.data.mongodb.core.query.Query methods and the MongoTemplate, something like this (Kotlin style, but I think you get the idea):

mongoTemplate.find(query(where("id").`in`(ids)).cursorBatchSize(1000), TheDocument::class.java, 'collection_name`)
Erik Finnman
  • 1,459
  • 18
  • 25