That wouldn’t work when you select the database id; the structure changes in the background. The ids for the filters are not the same even though the filter name looks the same. You cannot make it dynamic that way.
You may have to use the notion - make an API call. Check the documentation on using the search API