Browse Source

Update MongoDB.md

pull/15607/head
maliming 3 years ago
parent
commit
0f4719dca0
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 20
      docs/en/MongoDB.md

20
docs/en/MongoDB.md

@ -393,7 +393,7 @@ One advantage of using interface for a MongoDbContext is then it becomes replace
Once you properly define and use an interface for a MongoDbContext , then any other implementation can use the following ways to replace it:
**ReplaceDbContextAttribute**
#### ReplaceDbContext Attribute
```csharp
[ReplaceDbContext(typeof(IBookStoreMongoDbContext))]
@ -403,7 +403,7 @@ public class OtherMongoDbContext : AbpMongoDbContext, IBookStoreMongoDbContext
}
```
**ReplaceDbContext option**
#### ReplaceDbContext Option
```csharp
context.Services.AddMongoDbContext<OtherMongoDbContext>(options =>
@ -415,6 +415,22 @@ context.Services.AddMongoDbContext<OtherMongoDbContext>(options =>
In this example, `OtherMongoDbContext` implements `IBookStoreMongoDbContext`. This feature allows you to have multiple MongoDbContext (one per module) on development, but single MongoDbContext (implements all interfaces of all MongoDbContexts) on runtime.
#### Replacing with Multi-Tenancy
It is also possible to replace a DbContext based on the [multi-tenancy](Multi-Tenancy.md) side. `ReplaceDbContext` attribute and `ReplaceDbContext` method can get a `MultiTenancySides` option with a default value of `MultiTenancySides.Both`.
**Example:** Replace DbContext only for tenants, using the `ReplaceDbContext` attribute
````csharp
[ReplaceDbContext(typeof(IBookStoreDbContext), MultiTenancySides.Tenant)]
````
**Example:** Replace DbContext only for the host side, using the `ReplaceDbContext` method
````csharp
options.ReplaceDbContext<IBookStoreDbContext>(MultiTenancySides.Host);
````
### Customize Bulk Operations
If you have better logic or using an external library for bulk operations, you can override the logic via implementing `IMongoDbBulkOperationProvider`.

Loading…
Cancel
Save