Skip to content

feat: make the MongoDB database configurable - #84

Merged
traefiker merged 1 commit into
traefik:masterfrom
mmatur:feat/mongodb-database-flag
Oct 26, 2026
Merged

traefiker merged 1 commit into
traefik:masterfrom
mmatur:feat/mongodb-database-flag

Conversation

@mmatur

@mmatur mmatur commented Oct 26, 2026

Copy link
Copy Markdown
Member

The database was hardcoded to plugin. --mongodb-database (MONGODB_DATABASE) sets it, the default stays plugin.

A second deployment can then run on a copy of the catalog in its own database, with a user that has no access to plugin.

Part of traefik/hub-issues#3124

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused configuration change preserves existing defaults and has no identified blocking issues.

No open issues 🎉

What changed in this PR

Makes the MongoDB database configurable so separate deployments can use isolated catalog databases, while preserving plugin as the default.

Changes:

  • Adds --mongodb-database and MONGODB_DATABASE and passes the selected value into the MongoDB configuration.
  • Documents the new option and its default.
File Description
readme.md Documents the database flag and environment variable.
cmd/​internal/​mongo.go Defines the database option and wires it into the MongoDB configuration.

Review effort: Balanced

@darkweaver87 darkweaver87 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Possible improvement for later, take it directly from URI:

func buildClientOptions(cfg mongodb.Config) (*options.ClientOptions, string, error) {
        cs, err := connstring.ParseAndValidate(cfg.URI)
        if err != nil {
                return nil, "", fmt.Errorf("parsing MongoDB URI: %w", err)
        }

        clientOptions := options.Client().ApplyURI(cfg.URI).
                SetPoolMonitor(&event.PoolMonitor{Event: poolMonitor}).
                SetMonitor(otelmongo.NewMonitor())

        if !cs.MinPoolSizeSet {
                clientOptions.SetMinPoolSize(cfg.MinPool)
        }
        if !cs.MaxPoolSizeSet {
                clientOptions.SetMaxPoolSize(cfg.MaxPool)
        }
        if !cs.SocketTimeoutSet {
                clientOptions.SetSocketTimeout(2 * time.Second)
        }
        if !cs.ConnectTimeoutSet {
                clientOptions.SetConnectTimeout(10 * time.Second)
        }
        if !cs.ServerSelectionTimeoutSet {
                clientOptions.SetServerSelectionTimeout(10 * time.Second)
        }

        database := cs.Database
        if database == "" {
                database = defaultDatabase
        }

        return clientOptions, database, nil
}

I tested it locally.

@traefiker
traefiker merged commit 7e387cc into traefik:master Oct 26, 2026
6 checks passed
@mmatur
mmatur deleted the feat/mongodb-database-flag branch October 26, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement a new or improved feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants