Open Closed

Bug: MongoDB Payment module creates 'Plans' collection without 'DbTablePrefix' (should be 'PayPlans') #10475


User avatar
0
juan.acedo created

Description

When using the ABP Payment module with MongoDB, the Plan entity is persisted to a collection named Plans instead of PayPlans. The PaymentDbProperties.DbTablePrefix (default: "Pay") is not applied to the Plans collection, even though it is correctly applied to PaymentRequestsPayPaymentRequests.

This contradicts the official documentation which states:

MongoDB Collections: PayPaymentRequests, PayPlans

Environment

  • ABP Framework version: 10.1.0 (also reproduced on 10.0.0)
  • Database provider: MongoDB
  • Tiered/MVC or Blazor Server: Blazor Server
  • OS: Windows 11

Steps to Reproduce

  1. Create a new ABP application with the Payment module and MongoDB provider
  2. Ensure AbpPaymentMongoDbModule is loaded (either standalone or via ReplaceDbContext<IPaymentMongoDbContext>())
  3. Call modelBuilder.ConfigurePayment() in CreateModel() (as per documentation)
  4. Navigate to Payment > Plans admin UI and create a new Plan
  5. Check MongoDB collections

Expected Behavior

Both collections should have the "Pay" prefix applied by ConfigurePayment():

| Entity | Expected Collection | |--------|-------------------| | PaymentRequest | PayPaymentRequests | | Plan | PayPlans |

Actual Behavior

| Entity | Actual Collection | Prefix Applied? | |--------|------------------|-----------------| | PaymentRequest | PayPaymentRequests ✅ | Yes | | Plan | Plans ❌ | No |

The Plan entity is created in a collection named Plans (without the "Pay" prefix), while PaymentRequest correctly uses PayPaymentRequests.

Investigation

  • PaymentDbProperties.DbTablePrefix returns "Pay" (confirmed via IL metadata inspection of Volo.Payment.Domain.dll v10.1.0)
  • PaymentMongoDbContextExtensions.ConfigurePayment() has identical IL body size (199 bytes) in both v10.0.0 and v10.1.0, suggesting the bug exists in both versions
  • The abppkg.analyze.json in both versions shows base collection names Plans and PaymentRequests — the prefix is expected to be applied at runtime by ConfigurePayment()
  • IPaymentMongoDbContext exposes both Plans and PaymentRequests properties, both calling Collection<T>() which should resolve the configured collection name

Workaround

Explicitly override the collection name for Plan (and PaymentRequest for safety) after calling ConfigurePayment():

protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
    base.CreateModel(modelBuilder);

    modelBuilder.ConfigurePayment();

    // Workaround: force "Pay" prefix on Payment entities
    modelBuilder.Entity<Plan>(b =>
    {
        b.CollectionName = PaymentDbProperties.DbTablePrefix + "Plans";
    });
    modelBuilder.Entity<PaymentRequest>(b =>
    {
        b.CollectionName = PaymentDbProperties.DbTablePrefix + "PaymentRequests";
    });
}

Impact

  • Applications that rely on ConfigurePayment() to set collection names will have Plan entities stored in Plans instead of PayPlans
  • This causes inconsistency with PayPaymentRequests which is correctly prefixed
  • Custom repositories that hardcode "PayPlans" (as documented) will fail to find data
  • The SaaS Edition > Plan lookup works because it reads from wherever ABP writes, but the collection name does not match the documentation

2 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • This is a known issue/bug in the Payment module’s MongoDB model mapping (reproducible in v10.0.0 and v10.1.0 as you observed): the Plan entity’s MongoDB collection name is not being configured with PaymentDbProperties.DbTablePrefix, so it falls back to the default convention and ends up as Plans, while PaymentRequest correctly becomes PayPaymentRequests.
    • Workaround (recommended until fixed in a patch): keep your current override in your MongoDbContext’s CreateModel (or OnModelCreating equivalent for Mongo) and force the collection name for Plan (and optionally PaymentRequest) after calling modelBuilder.ConfigurePayment():
    protected override void CreateModel(IMongoModelBuilder modelBuilder)
    {
        base.CreateModel(modelBuilder);
    
        modelBuilder.ConfigurePayment();
    
        // Workaround: enforce prefix for collections that are incorrectly mapped
        modelBuilder.Entity<Volo.Payment.Plans.Plan>(b =>
        {
            b.CollectionName = PaymentDbProperties.DbTablePrefix + "Plans";
        });
    
        // Optional safety (this one is already correct in your case)
        modelBuilder.Entity<Volo.Payment.PaymentRequests.PaymentRequest>(b =>
        {
            b.CollectionName = PaymentDbProperties.DbTablePrefix + "PaymentRequests";
        });
    }
    
    • Result: New writes will go into PayPlans as documented (instead of Plans). If you already have data in Plans, you’ll need to migrate/rename the existing collection in MongoDB (ABP won’t automatically move documents).

    • If you want to keep the workaround minimal: only override Plan since PaymentRequest is already correct in your environment.

    Sources:

    • https://abp.io/docs/latest/modules/payment

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will fix it, your ticket has been refunded.

    Thanks.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.3.0-preview. Updated on February 26, 2026, 13:35
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.