Filtering a Dataset on the "Collections" Multi Reference Field in Stores App

Hi all.

I am building a repeater function from the Products collection in Wix Stores.

I want to be able to filter a dataset that is connected to the Products to CatA or CatB or CatC, as defined in the Collections field of the Products Collection. Obviously this cannot be done in the settings for the collection, as that doesn’t support OR functions, so I am trying to build the filter in JS.

However, the API is confusing as to how to filter on a multi-ref field - I can see the includes() approach won’t work, as that does not bring all the collection names across, so how should I approach this?

I guess I perhaps need to bypass the dataset approach and query the collection directly from code…but am still somewhat confused as to how I should build this, after wading through the documentation today.

Can anyone point me in the right direction??

Thanks,
Simon.

You can try

import wixData from 'wix-data';
// ...
$w.onReady(() => {
Promise.all([
wixData.queryReferenced("Categories", "categoryA-ID", "products"),
wixData.queryReferenced("Categories", "categoryC-ID", "products")
])
.then(r => {
const data = r[0].items.concat(r[1].items);
$w('#repeater').data = data;
})
})