Compare multiple fields in a dataset?

Is there anyway to sort through a dataset using multiple fields? for example:
wixData . query ( “CData” )
. eq ( “group” , group )
. eq ( “portraitOnly” , PortOnly )
. eq ( “portraitLandscape” , PortLand )
. find ()
. then (( results ) => {
let R esultNum = results . length ;
console . log ( ResultNum )

I would like to match multiple data fields in a single dataset. (If that makes sense)

If you mean filtering a dataset then yes, use the setFilter() function

is there anyway to filter the data before opening the dynamic page? I have a collection with several fields i would like to match. If there is 1 match, I want it to open a dynamic(product) page of that item. If there are more than 1, I would like it to open an (All) dynamic page with just that data.

I appreciate your help!

Hey Joey,

I recommend setting up a loader on the dynamic page until the processing is done, then show the actual content after that.

You can determine whether you want to show the page item or redirect to another page.

To get the current page item, you need to wait for the page and the dataset to get ready, then run your query afterward.

$w.onReady(() => {
    $w('#dataset').onReady(() => {
        const item = $w('#dataset').getCurrentItem();
        
        // Run your query here
        wixData.query('collection').eq('fieldId', item.value).find().then((x) => {
            if (x.length > 0) {
                // There are more than one item, redirect the user to another page
                wixLocation.to('<Your page URL>');
            } else {
                /* There's only matching item, hide the loader and show the page
                content, or redirect to another page if wish */
            }
        })
    })
})

Remember to import the wix-location module to be able to redirect the users.

Hope this helps~!
Ahmad

Thank you for your reply! My biggest issues is comparing multiple fields. Can I use multiple “.eq” statements? and what is the best way to integrate a loader?

I really appreciate your help!!

@joeycahill24 Yes you can use as many eqs as you want.

You can have a multi-state box with the default state being the initialization state with a gif or HTML loader, then change the state when the processing is done.