From a11155e3127b26bcc4e909300bf4187d42057153 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 14 Mar 2025 11:38:11 +0800 Subject: [PATCH 1/2] Update MongoDB documentation to enable transactions and add Docker setup instructions --- docs/en/framework/data/mongodb/index.md | 35 ++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/docs/en/framework/data/mongodb/index.md b/docs/en/framework/data/mongodb/index.md index 57532f4f59..97ad051b68 100644 --- a/docs/en/framework/data/mongodb/index.md +++ b/docs/en/framework/data/mongodb/index.md @@ -311,14 +311,37 @@ public class BookService MongoDB supports multi-document transactions starting from the version 4.0 and the ABP supports it. However, the [startup template](../../../solution-templates) **disables** transactions by default. If your MongoDB **server** supports transactions, you can enable the it in the *YourProjectMongoDbModule* class: -```csharp -Configure(options => -{ - options.TransactionBehavior = UnitOfWorkTransactionBehavior.Auto; -}); +Remove the following code to enable transactions: + +```diff +- context.Services.AddAlwaysDisableUnitOfWorkTransaction(); +- Configure(options => +- { +- options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; +- }); ``` -> Or you can delete this code since this is already the default behavior. +#### Create Test MongoDB in Docker to support transactions + +You can use below `docker-compose.yml` file to create a test MongoDB **ReplicaSet** instance that supports transactions, The connection string will be `mongodb://localhost:27017/YourProjectName?replicaSet=rs0`. + +```yaml +version: "3.8" + +services: + mongo: + image: mongo:8.0 + command: ["--replSet", "rs0", "--bind_ip_all", "--port", "27017"] + ports: + - 27017:27017 + healthcheck: + test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'127.0.0.1:27017'}]}) }" | mongosh --port 27017 --quiet + interval: 5s + timeout: 30s + start_period: 0s + start_interval: 1s + retries: 30 +``` ### Advanced Topics From 69e4b51b222d3352023efbba2d45c223c466d91e Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Fri, 14 Mar 2025 13:29:05 +0300 Subject: [PATCH 2/2] Update index.md --- docs/en/framework/data/mongodb/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/framework/data/mongodb/index.md b/docs/en/framework/data/mongodb/index.md index 97ad051b68..d5bb4124aa 100644 --- a/docs/en/framework/data/mongodb/index.md +++ b/docs/en/framework/data/mongodb/index.md @@ -309,7 +309,7 @@ public class BookService ### Transactions -MongoDB supports multi-document transactions starting from the version 4.0 and the ABP supports it. However, the [startup template](../../../solution-templates) **disables** transactions by default. If your MongoDB **server** supports transactions, you can enable the it in the *YourProjectMongoDbModule* class: +MongoDB supports multi-document transactions starting from the version 4.0 and the ABP supports it. However, the [startup template](../../../solution-templates) **disables** transactions by default. If your MongoDB **server** supports transactions, you can enable them in the *YourProjectMongoDbModule* class: Remove the following code to enable transactions: @@ -321,9 +321,9 @@ Remove the following code to enable transactions: - }); ``` -#### Create Test MongoDB in Docker to support transactions +#### Setting up a Transaction-Enabled MongoDB Replica Set in Docker -You can use below `docker-compose.yml` file to create a test MongoDB **ReplicaSet** instance that supports transactions, The connection string will be `mongodb://localhost:27017/YourProjectName?replicaSet=rs0`. +Use the following `docker-compose.yml` to create a local MongoDB Replica Set that supports transactions. The connection string will be `mongodb://localhost:27017/YourProjectName?replicaSet=rs0`. ```yaml version: "3.8" @@ -533,4 +533,4 @@ public class MyCustomMongoDbBulkOperationProvider * [Entities](../../architecture/domain-driven-design/entities.md) * [Repositories](../../architecture/domain-driven-design/repositories.md) -* [Video tutorial](https://abp.io/video-courses/essentials/abp-mongodb) \ No newline at end of file +* [Video tutorial](https://abp.io/video-courses/essentials/abp-mongodb)