无法在多文档事务中创建命名空间(MongoDB 4.0、Spring Data 2.1.0、Spring Boot)

这个问题是关于 Spring boot, Mongo4.0, Spring-data application.

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

我已从 MongoDB 3.6.x 升级到 MongoDB 4.0,并将 Spring data 2.0.x 升级到 Spring-data 2.1.0,以便在将数据插入多个文档时进行事务管理.但是在这里,我在创建数据库、集合并将文档插入集合时遇到了这个问题.

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.

Cannot create namespace sampledb_200.demo in multi-document transaction 

这里 sampldb_200 是数据库名称,demo 是集合名称.

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

在早期的 mongodb3.6.X 版本,Spring Data 2.0.x 中,即使数据库和集合不存在,我也能够同时进行数据库、集合创建、文档插入.

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.

使用 Spring Data 2.1.0、MongoDB 4.0,数据库、集合创建和插入不会发生在一个函数和数据库下,集合创建要显式完成.

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.

推荐答案

Spring 采用了 MongoDB 4.0 附带的一项新功能,该功能支持多文档事务.该功能仅适用于现有集合,即多文档事务不能包含会导致创建新集合的插入操作.您应该事先创建您的收藏以使用此功能.

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.

相关文章