Wixdata.query for an element within an array in collection

How can I query an array item in a query?
I am attempting to filter a repeater as long as items loaded State location equals the State location queried. However, I am unable to query an array field correctly. I have been able to simply query values in a collection that is not within an array, but attempting to grab information has me puzzled.

There are 2 collections: Members and Locations.

  1. Location contains State, county, city, etc.
  2. Members contains user information that includes the State from Location collection in an array.
export function memberResultsRepeater_itemReady($item, itemData, index) {

    let vendorTypeFromSession = session.getItem("sessionVendorType");
    let vendorTypesFromSession = session.getItem("sessionVendorTypes");
    let vendorLocation = session.getItem("sessionLocation");
    
    console.log("The State of vendor: " + itemData.profileName + " is " + itemData.address.subdivisions[0].name + ".");

    if (vendorLocation.length > 0) {
        $w("#dynamicDataset").setFilter(wixData.filter().eq("address.subdivisions[0].name", vendorLocation));
    }   
    else {
        console.log("Repeater not filtered. ");
        $w("#dynamicDataset").setFilter(wixData.filter().contains("VendorTypes", vendorTypesFromSession));
    }
 }

Results from my console.log confirms that I know how to get the user and their location attached to an item. However, my repeater comes up blank for loading users from a particular location.

This is the array field that I am attempting to filter by or query.

I have attempted to wixData.query, but also ran into the problem that I do not know how to point or map to this particular field in a query. Any assistance would be appreciated.

You can use this function to query member data:

wixData.query("Members/PrivateMembersData")
    .eq('location' yourVariable) //try and use your session here
    .limit(50) /*there is a max but cannot remember on top of my head --> normal collections are 1000 but member and stores are less */
    .find()
    .then( (results) => { 
        // handle the results  
    } );

You should also just query everything, filter the ones you want, then display in repeater all in code.

To display items from query in repeater, check this out – its great.

Code example:

import wixData from ‘wix-data’;

$w.onReady(async function () {
// Define how to set up each new repeater item
$w(‘#helloRepeater’).onItemReady( ($item, itemData, index) => {
$item(‘#languageText’).text = itemData.language;
$item(‘#helloText’).text = itemData.greeting;
$item(‘#indexText’).text = (index + 1).toString();

$item('#itemContainer').onMouseIn( () => {
  $item('#languageText').show();
});

$item('#itemContainer').onMouseOut( () => {
  $item('#languageText').hide();
});

} );

// Get data from a database collection
const {items: collectionData} = await wixData.query(‘Greetings’).find();
console.log(collectionData);

// Set the data to associate with the repeater
$w(‘#helloRepeater’).data = collectionData;
});

Thank you for the response. I have looked into using query opposed to filters, but my main issue still remains.

I am having trouble connecting “Members/PrivateMembersData” with the use of multi-reference type fields in the Collection. I am having trouble creating the query for this element specifically.

If you have any references regarding how to add them to a query, then it would be greatly appreciated.

If you want to include a reference point you need to use the " include" variable method – “.include(field key name for reference point)” – in your query or you you use the queryReferenced API. Note that including references drastically shortens the max limit you can call since the data object is considerably larger.