I’m using the Stores / Products and the Stores / Collections tables with wixData like so:
await wixData .query("Stores/Products") .hasSome("collections._id", [collectionID]) .find()
The result of this was the following error:
Error: {"message":"Unknown token collections._id -> Map($hasSome -> List(6229a2fb-c14d-82a5-e7ad-c5464086af33))","details":{}}
I’ve tried various different options in the hasSome, such as product . collections . _id and such as collections . id, but nothing seems to be working. Looking at the Stores / Products table, the Collections column has a field key of “collections” and a type of “Multi-Reference”. Adding in .include(“collections”) before the .hasSome() also doesn’t appear to change anything.
I did have a working version using wixSearch, but I couldn’t get it to sort:
await wixSearch .search() .documentType("Stores/Products") .hasSome("collections", [collectionName]) .ascending("_updatedDate").find()
I’m not sure the difference between wixData and wixSearch, so I don’t particularly care which one needs to be used, but neither is resulting in what I want.
*Note: I’ve had to put random spaces around some . and / because the forums think they are links.
I think you are trying to combine several steps at once and it is not working.
You need to break it down into steps
Step 1 — get the collections._id into a variable.
The nice thing is you can print to the console, using ‘console.log()’, the result to confirm you got the correct _id.
How are you getting the Stores/Colletions._id?
Step 2 — now that you have the correct id, use it to then query the ‘Stores/Products’.
If you still have a problem, then we can troubleshoot step 2.
I have a different wixData query that pulls all the Collections and use the ids from that response. A console.log confirms the id is still assigned right before the Products query. Removing the .hasSome() results in a working query, so I’m confident it’s the problem.
I just wanted to confirm that the Collections you pull in are not a key/value pair. The hasSome() specifies that the array of items (your Collection Ids) have to specifically be an array of strings. Eg: [“id1”, “id2”, “id3”]. They can’t be [{_id:“id1”, _id:“id2”, _id:“id3”}]. I wasn’t sure if you massaged the first query to ensure that you were using only an array of strings.
Hi, So not sure if you figured it out or got a response, but you don’t need to _id part. It would just be below and also not sure if the value can be an array. I just pass in an id string. But I’m having a different problem where the query is only querying like part of the database of Stores/Products. So I have over 6000 products and if I look at the database it self and look at the default view which has no filters, so it should be all of the products. It only shows me a little over 2000 products. which is really weird. and if I do the same filter on that as my query in code I get the same results. it returns me 67 products. If I do the same sort of filter in the dashboard/products where you can add new products and import them in, I’ll see almost 200 products which is actually the correct number. Not 67. Do you have this issue? Also you may need options in the query below to show certain fields.
const options = {
suppressAuth : true ,
// Include product variants in the query. Default is false
.
includeVariants : true ,
// Include hidden products in the query. Default is false
.
includeHiddenProducts : true
};
await wixData . query ( “Stores/Products” ). hasSome ( “collections” ,[ collectionID ]). find (options)