feat: add collectionPrefix option - #88
Conversation
There was a problem hiding this comment.
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
collectionPrefixconfiguration 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| const collectionNames = Object.fromEntries( | ||
| [ | ||
| 'subscriptions', | ||
| 'retained', | ||
| 'will', | ||
| 'outgoing', | ||
| 'incoming' | ||
| ].map(collectionName => [collectionName, `${collectionPrefix}${collectionName}`]) | ||
| ) |
There was a problem hiding this comment.
I would just do this in case collectionPrefix exists
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
collectionPrefixcollectionPrefix option
|
code and doc updated |
There was a problem hiding this comment.
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.
This PR adds the new parameter
collectionPrefixthat 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.