I am searching for a way to store conditions in mongodb, to be queried and checked, then do something as a result of the condition check.
First off here is an example of the event object that I am considering
{
"name": "My Event",
"created": 1490726092221,
"startDate": 1490726092221,
"endDate": 1490726097810,
"notifications": [
{
"message": "{event.Name} Created", // message template
"status": 0, // 0=initialized 1=failed 2=sent
"sendDate": null, // date that the notification was sent
"sentTo": ["c2a34dfg32c1d4583e73a123"] //members to send notification to
"criteria": {
"script": "event.created >= 0 && this.status < 2"
}
}
],
"members": [
{
"_id": "c2a34dfg32c1d4583e73a123" // Reference to the user
}
]
}
The use case, I want to have customizated notifications for an event. So if an event is scheduled it could have notifications for when it is created, when the event start date is within a few days, when a member joins etc. While I could code all of these into javascript functions and correspond to them by an enum for the notification criteria, or have hooks for when certain events happen, this seems like a strict approach.
What I am envisioning is possibly a scripting language that can be stored as a string on the document, which can be queried and evaluated, which will return a boolean to trigger the notification or not.
The script would need to have the event as an input variable, as well as a few special input variables to be available to the script.
This could be done with javascript and eval()
but that scares me. Are there any other tools that can be used for this use case? Or, are there any suggestions for a better approach to this problem?