I want to use the match pipeline stage to dynamically filter based on given parameters that may or may not be undefined when I call the function.
For example, if I passed in a JSON object to the function that contains a value for Field1, I would have a match pipeline like the following:
{
"$match": {
"Field1": Field1_value
}}
However, if I had a JSON object passed into the function that contains values for Field1 and Field 2, I would like to have a match pipeline like the following:
{
"$match": {
"Field1": Field1_value,
"Field2": Field2_value
}}
Is there a simple way to do this that wouldn't involve having to write static pipelines for each combination of fields that I pass to this function?