abp-mongodb
/abp-mongodb
ABP Framework v10.x (10.4–10.6) MongoDB: AbpMongoDbContext, collection mapping, index, transaction, replica set, repository. Use when working with MongoDB, document databases, or MongoDB repositories in ABP.
- Author
- burakdmir ↗
- Repository
- abp-skills ↗
- Licence
- MIT
- Last repository change
- 14.08.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 1
No signals detected. Repository changed on 14.08.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
ABP Framework v10.x (10.4–10.6) MongoDB: AbpMongoDbContext, collection mapping, index, transaction, replica set, repository. Use when working with MongoDB, document databases, or MongoDB repositories in ABP.
Original author description
ABP Framework v10.x (10.4–10.6) MongoDB: AbpMongoDbContext, collection mapping, index, transaction, replica set, repository. Use when working with MongoDB, document databases, or MongoDB repositories in ABP.
How it works
- Trigger
- Installation
- MongoDbContext
- DbContext Registration
- Custom Repository
- MongoDB API Access
- Transactions
- EF Core vs MongoDB
- Best Practices
- v10.5+
SKILL.md preview
---
name: abp-mongodb
description: "ABP Framework v10.x (10.4–10.6) MongoDB: AbpMongoDbContext, collection mapping, index, transaction, replica set, repository. Use when working with MongoDB, document databases, or MongoDB repositories in ABP."
---
# ABP Framework — MongoDB
ABP Framework v10.x (10.4–10.6) MongoDB integration. MongoDbContext, collection mapping, repository, indexes, transactions.
## Trigger
- "ABP MongoDB"
- "ABP MongoDbContext"
- "ABP Mongo repository"
- "ABP Mongo collection"
- "ABP Mongo index"
- "ABP Mongo transaction"
## Installation
```bash
abp add-package Volo.Abp.MongoDB
```
```csharp
[DependsOn(typeof(AbpMongoDbModule))]
public class MyModule : AbpModule { }
```
## MongoDbContext
```csharp
public class MyDbContext : AbpMongoDbContext
{
public IMongoCollection<Question> Questions => Collection<Question>();
public IMongoCollection<Category> Categories => Collection<Category>();
protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
base.CreateModel(modelBuilder);
modelBuilder.Entity<Question>(b => { b.CollectionName = "MyQuestions"; b.BsonMap.UnmapProperty(x => x.MyProperty); });
}
}
```
Or via attribute: `[MongoCollection("MyQuestions")]`
### Index
```csharp
modelBuilder.Entity<Question>(b =>
{
b.CreateCollectionOptions.Collation = new Collation(locale: "en_US", strength: CollationStrength.Secondary);
b.ConfigureIndexes(indexes => indexes.CreateOne(new CreateIndexModel<BsonDocument>(Builders<BsonDocument>.IndexKeys.Ascending("MyProperty"), new CreateIndexOptions { Unique = true })));
});
```
## DbContext Registration
```csharp
context.Services.AddMongoDbContext<MyDbContext>(options => options.AddDefaultRepositories());
```
## Custom Repository
```csharp
public interface IBookRepository : IRepository<Book, Guid> { Task DeleteBooksByTypeAsync(BookType type); }
public class BookRepository : MongoDbRepository<MyMongoDbContext, Book, Guid>, IBookRepository
{
public BookRepository(IMongoDbContextProvider<MyMongoDbContext> dbContextProvider) : base(dbContextProvider) { }
public async Task DeleteBooksByTypeAsync(BookType type)
{
var collection = await GetCollectionAsync();
await collection.DeleteManyAsync(Builders<Book>.Filter.Eq(b => b.Type, type));
}
}
```
## MongoDB API Access
```csharp
IMongoDatabase db = await _repository.GetDatabaseAsync();
IMongoCollection<Book> coll = await _repository.GetCollectionAsync();
IAggregateFluent<Book> agg = await _repository.GetAggregateAsync();
```
## Transactions
MongoDB 4.0+ supports transactions. In the startup templates they are **disabled by default**.
**Enable:** In `YourProjectMongoDbModule`, remove the `AddAlwaysDisableUnitOfWorkTransaction()` and `TransactionBehavior = Disabled` code.
**Docker Replica Set:**
```yaml
services:
mongo:
image: mongo:8.0
command: ["--replSet", "rs0", "--bind_ip_all", "--port", "27017"]
ports: [27017:27017]
```
Connection: `mongodb://localhost:27017/YourProjectName?replicaSet=rs0`
## EF Core vs MongoDB
| Feature | EF Core | MongoDB |
|---|---|---|
| DbContext | `AbpDbContext<T>` | `AbpMongoDbContext` |
| Query | `IQueryable` (LINQ) | Filter/Aggregate |
| Transaction | Enabled by default | Disabled by default |
| Change Tracking | Yes | No |
| Extra Properties | JSON field | Native element |
## Best Practices
1. Use `AbpMongoDbContext`
2. Define collection names with `[MongoCollection]`
3. Define indexes in `CreateModel`
4. Set up a replica set for transactions
5. Define custom repositories in the MongoDB layer
## v10.5+
- MongoDB.Driver upgraded to 3.9.0 — align direct driver pins with ABP's version.
## v10.6+
- MongoDB.Driver upgraded to 3.10.0 — align direct driver pins with ABP's version.
## Related
[DDD](../abp-ddd/SKILL.md) · [EF Core](../abp-efcore/SKILL.md) · [Dependency Rules](../abp-dependency-rules/SKILL.md) · [Multi-Tenancy](../abp-multitenancy/SKILL.md) · Docs: https://abp.io/docs/latest/framework/data/mongodb
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · burakdmir/abp-skills | 100 | MIT |
| burakdmir/abp-skills | 100 | MIT |
Database snapshot: 13.11.2026 · package version 11565f2fe831 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Similar skills
- 100mongodb-integration
Integrate MongoDB into an ABP application: AbpMongoDbContext, collection mapping, AddMongoDbContext registration, and custom Mongo repositories. USE FOR: defining an AbpMongoDbContext, mapping collections with [MongoCollection]/CreateModel, registering via AddMongoDbContext,… - 98abp-cli
ABP Framework v10.x (10.4–10.6) CLI and tooling: abp new, add-package, generate-proxy, ABP Studio, ABP Suite, --modern flag. Use when working with ABP CLI commands, creating projects, adding packages, or generating proxies. - 100spring-data-mongodb
Spring Data MongoDB for Java/Spring Boot applications. Covers repositories, MongoTemplate, aggregations, and document mapping. USE WHEN: user mentions "spring data mongodb", "MongoTemplate", "MongoRepository", "@Document", "Spring Boot MongoDB", "aggregation pipeline Java" DO… - 98abp-cli
ABP Framework v10.x (10.4–10.6) CLI and tooling: abp new, add-package, generate-proxy, ABP Studio, ABP Suite, --modern flag. Use when working with ABP CLI commands, creating projects, adding packages, or generating proxies. - 100mongodb
Administer MongoDB databases. Configure replica sets, sharding, and backups. Use when managing MongoDB deployments. - 100mongodb
Administer MongoDB databases. Configure replica sets, sharding, and backups. Use when managing MongoDB deployments.