Skip to content
Skills Library
Programming · Building & coding

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.

Repository
abp-skills ↗
Licence
MIT
Last repository change
14.08.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 14.08.2026, without references to retired models or APIs.

Licence

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

  1. Trigger
  2. Installation
  3. MongoDbContext
  4. DbContext Registration
  5. Custom Repository
  6. MongoDB API Access
  7. Transactions
  8. EF Core vs MongoDB
  9. Best Practices
  10. v10.5+
Original SKILL.md headings · 129 lines, 386 words
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

RepositoryScoreLicence
This page · burakdmir/abp-skills100MIT
burakdmir/abp-skills100MIT

Database snapshot: 13.11.2026 · package version 11565f2fe831 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

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.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.