Trying to populate dropdown using the result of mongo query

I have created a grafana application. I am using the variables function and within that, I have the option to return a query which populates the dropdown. I have tested the query in a normal table panel and it returns the correct values. Using this in the query in the variables section doesn’t work.

Additionally and potentially more importantly, since mongo is not used by default as a datasource for Grafana, I have to install a plugin which is linked:

What would be the best way to achieve what I am doing? Any help appreciated. Thanks!