Skip to content

feat: add collectionPrefix option - #88

Merged
robertsLando merged 9 commits into
moscajs:masterfrom
mrzenw-gap-env:master
Oct 1, 2025
Merged

feat: add collectionPrefix option#88
robertsLando merged 9 commits into
moscajs:masterfrom
mrzenw-gap-env:master

Conversation

@MrZenW

@MrZenW MrZenW commented Sep 27, 2025

Copy link
Copy Markdown
Contributor

This PR adds the new parameter collectionPrefix that allows users to organise collections as their own.

It allows devs to host multiple brokers within a single MongoDB database without the need for creating multiple databases. However, if devs prefer to split the datastore into separate databases, they can still do using db or url.

Copilot AI review requested due to automatic review settings September 27, 2025 12:04

Copilot AI 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.

Pull Request Overview

This PR adds support for a collectionPrefix parameter to allow users to customize the naming of MongoDB collections by adding a prefix to the default collection names.

  • Introduces a new optional collectionPrefix configuration parameter
  • Updates collection initialization to use prefixed names when the parameter is provided
  • Refactors collection name management using a reduce function to build the collection names object

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread asyncPersistence.js
Comment thread asyncPersistence.js Outdated
MrZenW and others added 2 commits September 28, 2025 00:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@robertsLando robertsLando left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please also update docs

Comment thread asyncPersistence.js Outdated
Comment on lines +94 to +102
const collectionNames = Object.fromEntries(
[
'subscriptions',
'retained',
'will',
'outgoing',
'incoming'
].map(collectionName => [collectionName, `${collectionPrefix}${collectionName}`])
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would just do this in case collectionPrefix exists

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.

Biggest question (also asked by @robertsLando) would be "what is the use case". As you can already specify a different database and hosting multiple Aedes servers in the same database sounds a bit special.

Kind regards,
Hans

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.

As to the code itself:more clearly would imho be:

    const subscriptions = db.collection(`${collectionPrefix}subscriptions`)
    const retained = db.collection(`${collectionPrefix}retained`)
    const will = db.collection(`${collectionPrefix}will`)
    const outgoing = db.collection(`${collectionPrefix}outgoing`)
    const incoming = db.collection(`${collectionPrefix}incoming`)

as it avoids the intermediate object.
It will only be called during setup, so performance is not an issue.

Kind regards,
Hans

@MrZenW MrZenW Sep 30, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It allows devs to host multiple brokers within a single MongoDB database without the need for creating multiple databases. However, if devs prefer to split the datastore into separate databases, they can still do using db or url.

@robertsLando robertsLando changed the title Add the new parameter collectionPrefix feat: add collectionPrefix option Sep 29, 2025
@MrZenW

MrZenW commented Sep 30, 2025

Copy link
Copy Markdown
Contributor Author

code and doc updated

@MrZenW
MrZenW requested a review from Copilot September 30, 2025 23:34

Copilot AI 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.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@MrZenW
MrZenW requested a review from robertsLando September 30, 2025 23:34
@robertsLando
robertsLando merged commit cac8cdf into moscajs:master Oct 1, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants