WixData.Query limits at max. 100 - how to only get 100 inStock = true Products?

Hi there
i was implementing an API Endpoint where i was querying the wixData . query ( “Stores/Products” ). This is by default limited to 50 items. I then overwritten it to 100 items which is the max according to API documentation.

now i’m getting 100 products, some of them are not in stock, some of them are. how can i get 100 products which are in stock only?

i tried to eq() but it gives me an error:

wixData.query("Stores/Products")
        .eq('inStock', true)
        .limit(100)
        .find()
{"error":{"name":"Error","errorGroup":"User","code":"WDE0076"}}

Can anyone help me out here?

Thx & cheers

boesee

You have the DATABASE-FIELD → “inStock” in your DB.
Of which kind of type is it? —> STRING or BOOLEAN ?

Your code-(excerpt) seems to be ok.

$w.onReady(()=>{
	wixData.query("Stores/Products")
	.eq('inStock',true) //works on boolean field
	//.eq('inStock',true) //works on string field
	.limit(100)
	.find()
	.then((res)=>{
		console.log(res);	
	}).catch((err)=>{console.log(err);});
});

Yes, “Stores/Products” is a Wix standard DB and attribute ‘inStock’ exists and is a boolean.

your code snippet is exactly what i posted in my original post, resulting in the error stated in the original post.

  1. Check if it would work without → filter ----> . eq ( ‘inStock’ , true )
  2. Try to query from BACK-END not from FRONT-END

That error code is a validation error so perhaps due to something else? https://www.wix.com/velo/reference/wix-data/error-codes

According to the documentation, the “inStock” field cannot be filtered on.

" Description : Indicates whether the product is in stock.
Type : Boolean
Can connect to data : Yes
Can use in dynamic page URL : No
Can be sorted : No
Can be filtered : No
Read-only : Yes
"

doc reference: https://support.wix.com/en/article/velo-wix-stores-products-collection-fields

If you set the product visibiltiy to hidden in the product dashboard, it shouldn’t show in your store anymore though

That’s probably it. But i wonder why it’s not filterable… Doesn’t make sense to me.

I know, but the visability is not the problem, i want to return available-only products in my api endpoint. Since it’s limited I want to usefully use the capacity given.

So the mystery is solved.

I already assumed it here…

If you are a mainstream-coder → your way end here.
If you are a genius custom-coder–> your adventures just starts here at this point.

Yes, you want to provide the filtered DATA to another SITE by generating an END-POINT. And yes you have a problem now.

But what about a WORKAROUND ?

What about just quering all data without filtration first.
And do the filterings by your own with your own generated CUSTOM-CODE ???
Be more flexible and use your fantasy + brain and you will get something like…

  1. How to filter objects?
  2. How to filter arrays including objects?

I don’t want to search the whole web for you to find something what will fit your needs, this will be your own task.

Start your coding-adventure right now and find your WORKAROUND to solve your problem.

When you have 150 products of which 95 are available and 55 aren’t. You’re wix query result set contains the first 100 rows ordered by created date descending (default). How do make sure, that you got all the 95 available products? filtering afterwards only filters those first 100 rows. So your solution solves problems, but not mine, mainstream coder :wink:

First you do several queries to collect all data and put it into one unique array.
Then you do all fiterings you want (chuncked + joined data).

I understand that you do not understand, no problem.
Anyway good luck.

Good luck.

ok, so let me see your suggestion.

How do you get the full data over multiple queries for the collection “stores/products”. I am geniously wondering…

Yes, of course you are “geniously wondering” and you would do it THE NEXT 5-YEARS , if i wouldn’t be a nice person. Well everyone should get his second chance…

What you can do?

  1. Do a normal query for 100-items.
  2. Console-log the RESULTS you get.
  3. Are you able to find “hasNext”.

If “hasNext” exists → than you can use a → “DO-WHILE-LOOP”…
…something like …

let allItems = results.items;
while(results.hasNext())
	{results =await results.next();
		allItems = allItems.concat(results.items);
	}
	return allItems;
}

Just a pseudo-code-example for you. You will have to expand modify and optimize it.

  1. The other way would be to use SKIP + LIMIT (if this function is included), normaly it should be available.

  2. If so generate a function which would generate a sequential query adding more and more items to your QUERY.

  3. Once you have your FULL-QUERY → you can start to generate your own custom FILTER-FUNCTION.

But first take a look which options you get from the resulting query, by inspecting the results in the CONSOLE.

If you need more infos, type in —“1000” into the search of the VELO-FORUM and get more infos about how to query a bigger DATABASE.

Good luck !!!

UPDATE:


Since few couple of days/weeks, the structure of the Wix-Data-Results has been changed → improvements have been done.

Take a look onto the pic for reference…

Are you able to find those similar results on your ordinary query-results?