Browse Source

Merge pull request #22374 from abpframework/auto-merge/rel-9-1/3540

Merge branch dev with rel-9.1
pull/22379/head
maliming 1 year ago
committed by GitHub
parent
commit
5b3735c063
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 39
      docs/en/framework/data/mongodb/index.md

39
docs/en/framework/data/mongodb/index.md

@ -309,16 +309,39 @@ 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:
```csharp
Configure<AbpUnitOfWorkDefaultOptions>(options =>
{
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Auto;
});
Remove the following code to enable transactions:
```diff
- context.Services.AddAlwaysDisableUnitOfWorkTransaction();
- Configure<AbpUnitOfWorkDefaultOptions>(options =>
- {
- options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled;
- });
```
> Or you can delete this code since this is already the default behavior.
#### Setting up a Transaction-Enabled MongoDB Replica Set in Docker
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"
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
@ -510,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)
* [Video tutorial](https://abp.io/video-courses/essentials/abp-mongodb)

Loading…
Cancel
Save