how_to_add_modify_email_topics
How to Add or Modify Email Topics in MongoDB
Author: Cansu Moran
Email topics are stored in the email_service
collection within the WFP database. To add or modify a topic, follow these steps:
Prerequisites:
- You need access to MongoDB, either through a MongoDB UI (e.g., MongoDB Compass) or through a command-line interface.
- You need the
template_id
, which corresponds to the object ID (_id
field) of a template related to the topic. You can find this in theemail_service > templates
collection.
Steps to Add/Modify an Email Topic:
-
Navigate to the
email_service
collection: Inside the WFP database, go to theemail_service
collection. This is where all email topics are stored. -
Add a New Topic or Modify an Existing One:
-
To add a new topic: Insert a new document with the following fields:
topic_name
: A unique identifier for the topic (e.g.,test_daily_reports
).template_id
: The object ID of the related template. You can find this ID in theemail_service > templates
collection under the_id
field.topic_display_name
: A human-readable name for the topic (e.g.,"Country Summary Report(s)"
). This will be the name that is included in the emails and the dropdown options during subscription.topic_description
: A short description of the topic (e.g.,"Daily Reports"
).options_available
: A boolean value indicating whether the topic has different subscribable options (e.g.,true
orfalse
).
Example document for a new topic:
{
"topic_name": "daily_reports",
"template_id": "000000000000000000000000",
"topic_display_name": "Country Summary Report(s)",
"topic_description": "Daily Reports",
"options_available": true
} -
To modify an existing topic:
- Use the
topic_name
to locate the topic. - Edit the fields as needed (e.g., changing
template_id
,topic_display_name
, etc.). - In MongoDB Compass, click on the document to edit it. In the CLI, use the
update
orfindAndModify
command.
Example of a MongoDB update command:
db.email_service.update(
{ "topic_name": "test_daily_reports" },
{ $set: { "topic_display_name": "Updated Country Summary Report" } }
) - Use the
-
3Understanding the options_available
Field:
options_available
is a boolean value that indicates whether users can subscribe to different options within the topic.- If
options_available
istrue
, it means the topic supports different subscription options (e.g., a user can subscribe to daily reports for specific countries). - If
options_available
isfalse
, it means the topic has a single subscription option, and all users subscribing to the topic will receive the same report (e.g., a Global Report topic).
- If
Key Points:
template_id
: Thetemplate_id
refers to the ObjectId of a template from theemail_service > templates
collection. Ensure that the template exists and is correctly linked to the topic.options_available
: This should be set totrue
for topics with multiple subscription options (like Daily Reports for different countries), andfalse
for topics with a single report (like a Global Report).