WixData Validation Error!

Hi there :raised_hand_with_fingers_splayed:

I was trying with this for hours now, and can’t figure out why I’m receiving this error!
Here’s the code:

export function getCalculatedRelatedItems(discountedPrice, name, itemsToGet) {    
    let maxPrice = (Number(discountedPrice) * 20 / 100) + Number(discountedPrice);
    let minPrice = Number(discountedPrice) - (Number(discountedPrice) * 20 / 100);   

    return wixData.query('Stores/Products').contains('name', name).le('discountedPrice', maxPrice).and(wixData.query('Stores/Products').contains('name', name).ge('discountedPrice', minPrice)).limit(itemsToGet).find({suppressAuth: true}).then((result) => {
        if (result.length > 0) {
            return result.items;
        } else {
            return [];
        }
    }).catch(err => {
        console.error(err);
        return [];
    })
}

The error that I’m getting from the catch method:

Object = {
    name: "Error",
    errorGroup: "User",
    code: "WD_VALIDATION_ERROR"
}

Here’s the error that I get when I remove the catch method:

Object = {
    message: "Unknown token discountedPrice -> Map($lte -> 600)",
    details: {} // Empty Object
}

Any ideas what’s the reason behind this? Any help is really appreciated!
Thanks in advance.

Ahmad

I believe this is because the Stores/Product collection is an external database and does not support all opération

as you can see here you cannot filter based on that discountedPrice.

My advice would be to create an index of productId vs discountedPrice that you query to get the productId then filter Stores/Products based on the Id you retrieved.

You can automate the syncing of products with events on wix-store-backend.

Let me know how it goes

Oh! Thank you very much @plomteuxquentin :wink: I knew it’s gonna be something simple but never expected it to be like this :joy:

I’m running this code on the backend with a for loop, I’m just going to validate the max/min values of each product and insert the passed ones into another array.

Again, thanks heaps.