I have a “MongoDB Aggregation” where I’m currently hardcoded a few parameters in $match etc inside the pipeline. If there’s any changes on the parameters, I need to modify their values inside the pipeline, which is quite tedious.
I come across “Variable Creator” and “String Configuration” components in KNIME so I thought maybe I can use that and pass the variables into MongoDB Aggregation through “Variable Inport”. However, it seems like I can’t use those variables in aggregation pipeline. Only can use them in:
Settings > Database
Settings > Collection, and
Flow Variables > pipeline
Appreciate if you guys can advice on how to use variable in the aggregation pipeline. Thanks in advance for your help!
The pipeline setting can be controlled via flow variable in the “Flow Variables” tab of the MongoDB Aggregation node’s configuration dialog. So you can first build the pipeline expression dynamically, e.g. using a String Manipulation (Variable) node, then give that to the MongoDB Aggregation node via String flow variable.
Hi @AlexanderFillbrunn, thanks for the suggestion! It never come across my mind to do that. However, if I want to build the pipeline expression dynamically, it seems like the String Manipulation (Variable) node doesn’t support if-else logic (do correct me if I’m wrong).
Is there any other way to do that before going through String Manipulation (Variable) node and pass it to MongoDB Aggregation node?