WixData error Too many children (insert_num_here) for logical operator

Hey!

I’m working on a project where products are saved to multiple lists.
The current implementation is as follows:

  • A user can create a list (the list has an id)
  • A user can add a product to a list
    → this is being done via a reference to the list database.
    → two DB tables. Lists and ProductListReference which is a product ID ref to Store/Products .
    → these are also member specific and don’t allow lists to bleed in from other users.

Right now I’m suffering with a bizarre error which there doesn’t appear to be much information on.

The error happens when I add more than about (8) items to the list. It works fine with about 1 - 5 items that I’ve tested, not sure what the cut off point is but not sure that matters.

The error is as follows:

Error: {
    "message": "Too many children (10) for logical operator",
    "details": {}
}

I have narrowed down the error to the following bit of code:

let query = wixData.query(DB_STORE_PRODUCTS).eq('_id', productList[0].productId);
for (let i = 1; i < productList.length; i++) { query = query.or(wixData.query(DB_STORE_PRODUCTS).eq('_id', productList[i].productId)); }

query.find().then(results => // <- THE ERROR HAPPENS SOMEWHERE IN HERE
{
	console.log("This will not execute");
	// code here
})
.catch(error => console.error);

It appears to be something wrong with the query.

Any help is greatly appreciated.

Kind regards,
Blake

If anyone happens to come across this issue, I think I solved it.

The issue appears to be this line specifically:

for(let i = 1; i < productList.length; i++){ query = query.or(wixData.query(DB_STORE_PRODUCTS).eq('_id', productList[i].productId));}

wixData doesn’t seem to like looping through a certain amount of times to construct a query. In fact this is just a terrible way of trying to solve the problem.

To solve, I extracted what I needed from the object, IE the productId…
Then I created a array of those productId’s, and used the wixData query hasSome() as follows:

let product_ids = [];
productList.forEach(product => product_ids.push(product.productId));

let items = (await wixData.query(DB_STORE_PRODUCTS).hasSome('_id', product_ids).find()).items;

Remember: hasSome() and hasAll() loops through arrays! Who knew?