Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create namespace in multi-document transaction(MongoDB 4.0, Spring Data 2.1.0, Spring Boot)

This question regarding to Spring boot, Mongo4.0, Spring-data application.

I have upgraded from MongoDB 3.6.x to MongoDB 4.0 and Spring data 2.0.x to Spring-data 2.1.0 for transactional management while inserting data into multiple documents. But here I face this issue while creating a database, collection and inserting a document into the collection.

Issue

Cannot create namespace sampledb_200.demo in multi-document transaction 

Here sampldb_200 is database name and demo is the collection name.

In earlier mongodb3.6.X versions, Spring Data 2.0.x, I was able to do database, collection creation, document insertion simultaneously even database and collection do not exist.

Using Spring Data 2.1.0, MongoDB 4.0, Database, collection creation, and insertion does not happen under one function and database, collection creation to be done explicitly.

like image 996
Srini Avatar asked Oct 01 '18 06:10

Srini


1 Answers

Spring is embracing a new feature shipped with MongoDB 4.0 that supports multi-document transactions. That feature works only for existing collections, ie, a multi-document transaction cannot include an insert operation that would result in the creation of a new collection. You should create your collections before hand to use this feature.

like image 138
Pablo Burgos Avatar answered Sep 18 '22 15:09

Pablo Burgos