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 (_idfield) of a template related to the topic. You can find this in theemail_service > templatescollection.
Steps to Add/Modify an Email Topic:
-
Navigate to the
email_servicecollection: Inside the WFP database, go to theemail_servicecollection. 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 > templatescollection under the_idfield.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.,trueorfalse).
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_nameto 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
updateorfindAndModifycommand.
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_availableis a boolean value that indicates whether users can subscribe to different options within the topic.- If
options_availableistrue, it means the topic supports different subscription options (e.g., a user can subscribe to daily reports for specific countries). - If
options_availableisfalse, 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_idrefers to the ObjectId of a template from theemail_service > templatescollection. Ensure that the template exists and is correctly linked to the topic.options_available: This should be set totruefor topics with multiple subscription options (like Daily Reports for different countries), andfalsefor topics with a single report (like a Global Report).