Gallery Not Displaying Filtered Results?

I am trying to populate a gallery with images from a database using wix code. From my console logging, it appears that the gallery is populated BEFORE the filtering is completed.

In my dataset connection to the gallery I set a filter such that no images would display, thereby letting me choose with code which images appear on the gallery. If I hard-code the roundup# and category, the correct images are populated in the gallery. So I know the gallery is setup properly and the images are being retrieved from the database.

Here is the last few lines of the JDeveloper Console…

Loading the code for the Roundup Photos popup. To debug this code, open va6me.js in Developer Tools.
console.js:35 RU Num: 25
console.js:35 RU Title: 2004 Roundup
console.js:35 Category: Sights
console.js:35 [onReady callback registered] on wix-dataset
console.js:35 [Dataset - Connected] ‘CVOA-Roundup-Photos’ collection to element ‘#gallery1’: Object
console.js:35 [Dataset - Populated] ‘CVOA-Roundup-Photos’ collection into element ‘#gallery1’: Array(0)
console.js:35 [datasetReady event] triggered on wix-dataset
console.js:35 Filtering on Roundup/Category: 25 / Sights
console.js:35 Found 37 Images in Category: Sights

I tried adding a preload function of 5 seconds but it did not work?

Here is the page code:

import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;
import wixLocation from ‘wix-location’;
import wixUsers from ‘wix-users’;
import { session } from ‘wix-storage’;
import {local} from ‘wix-storage’;

$w.onReady( () => {

let ru_cat = session.getItem(“Category”);
let ru_year = session.getItem(“Year”);
let ru_no = session.getItem(“Roundup”);

function preLoad(){
setTimeout(() => {
}, 5000);
}
console.log(“RU Num: " , ru_no)
console.log(“RU Title: " , ru_year)
console.log(“Category: " , ru_cat)
$w(”#roundupTitle”).text = ru_year;
$w(”#roundupNum").text = ru_no;
$w(“#category”).text = ru_cat;

$w(‘#dataset2’).onReady( () => {

wixData.query(‘CVOA-Roundup-Photos’)
.eq(‘roundup’, ru_no)
.eq(‘category’, ru_cat)
.find()
.then(res => {
console.log("Filtering on Roundup/Category: " , ru_no, “/”, ru_cat)
let resultCount = res.totalCount;
let found = resultCount;
if (found === 0) {
console.log("NO Match On Category: " , ru_cat)
}
else {
console.log("Found ", found ,"Images in Category: " , ru_cat)
}
} )
.catch( (err) => {
console.log(err);
} )
preLoad();
});
});

I have read all the documentation and examples and just don’t see where I went wrong?

Any help is greatly appreciated.
JD

Site: https://cosworthvega.com/roundup-photos ( ONLY have photos populated for 1st one - #25 )

Problem Solved. Changed code from data query to
$w(“#dataset2”).setFilter(wixData.filter()
Now its working as expected.