Hi can we store mongo db queries in mongo db document and later evaluate them with parameters? Currently it doesn’t work. Please see the details in this link.
Basically a document will have a query and I want to find the result of that query by giving parameters at run time in aggregation.
Then you write a function that takes the stored query and the query map. This function goes over the stored query and replace each instance of a place holder with the current value from the query map.
function map_dynamic_query( stored_query , query_map )
{
for stored_value in stored_query
{
if stored_value starts with @
{
dynamic_value = query_map.find( stored_value )
replace stored_value with dynamic_value
}
}
}
Running the above function with the above stored_pipeline and query_map would produce an executable query such as: