Filtering a Database on a Referenced Field

I have a database of drawing details (“detail database”) which has a reference field of tags (“tag field”) based on another “tags database”. I have created a dropdown list from the tags database. I want to create a filter based on the selection from the dropdown list which will sort against the tag field in the detail database. I have done the following:

tag = $w(‘#dropdownList’).value;
newFilter = newFilter.contains(‘tags’, tag);
$w(‘#detailDatabase’).setFilter(newFilter);

This works when the tags field is of type Text but not when its a Reference field. I know it has something to do with the fact that the ‘tags’ parameter is an array of string when a Reference type, but I don’t know how to represent it correctly when creating a new filter.

Any ideas?

Have you read the Wix Support pages about this already?
https://support.wix.com/en/article/displaying-content-from-multiple-database-collections-using-reference-fields-4034931#connecting-dropdown-elements-to-reference-fields

Have you looked for previous forum posts that could help you?
https://www.wix.com/corvid/forum/community-discussion/table-with-multiple-dataset-filtering
https://www.wix.com/corvid/forum/community-discussion/filter-a-table-with-dropdown-of-a-referenced-database
https://www.wix.com/corvid/forum/community-discussion/filter-results-by-reference-field-contains
https://www.wix.com/corvid/forum/community-discussion/filtering-by-reference-fields

As you use the Wix Data query function of .contains
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#contains

You can use contains() with a property whose value is a String or a Reference. For properties of type reference it is recommended that you use the eq() function instead of contains().

With properties that are References, contains() matches by the ID of the referenced item as a String.