Help with database collection filter

I’m trying the create a filter for a training course database.

The idea was to use the filter to find courses by course title and use a category select drop down menu to cross reference the data.

Currently with the code I have this is the result I keep getting.

I created two collections, 1 holds the training course information and the other is being used as a reference for the course categories.

Would be very grateful if someone could help.

Courses collection

Categories collection


Current code

import wixData from "wix-data";

$w.onReady(() => {
    wixData.query('Courses')
        .find()
        .then(res => {
 let options = [{"value": '', 'label': 'All Courses'}];
            options.push(...res.items.map(courses => {
 return {'value': courses.category, 'label': courses.category};
            }));
            $w('#iCategory').options = options;
        })
});

let lastFilterTitle;
let lastFilterCourses;

let debounceTimer;
export function iTitle_keyPress(event, $w) {
 if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    }
    debounceTimer = setTimeout(() => {
        filter($w('#iTitle').value, lastFilterCourses);
    }, 200);
}

function filter(title, category) {
 if (lastFilterTitle !== title || lastFilterCourses !== category) {
 let newFilter = wixData.filter();
 if (title)
            newFilter = newFilter.contains('title', title);
 if (category)
            newFilter = newFilter.eq('category',category);
        $w('#dataset1').setFilter(newFilter);
        lastFilterTitle = title;
        lastFilterCourses = category;
    }
}

export function iCategory_change_1(event, $w) {
    filter(lastFilterTitle, $w('#iCategory').value);
}

Hello.

You should try to reference the ID field of the Categories collection by changing the code below:

$w.onReady(() => {
    wixData.query('Categories')
        .find()
        .then(res => {
 let options = [{"value": '', 'label': 'All Courses'}];
            options.push(...res.items.map(categories => {
 return {'value': categories._id, 'label':categories.title
 };
            }));
            $w('#iCategory').options = options;
        })
});

Then for the category filter:

if (category)
            newFilter = newFilter.hasSome('category',category);

Good luck!