I use wixData to get the record from Stores/Products as below
import wixData from 'wix-data'; wixData.query("Stores/Products").limit(15).find() .then( (results) => { console.log(results.items); } );
However in the results returned, I cannot get the collections properties. Please help.
You would need to put an actual data query function into the code example from the Wix Stores pages themselves as shown here.
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html
https://support.wix.com/en/article/corvid-wix-stores-products-collection-fields
To use the Products collection in code, refer to it as “Stores/Products”.
wixData.query("Stores/Products")
//your data query function goes here//
.find()
.then( (results) => {
// handle the results
} );
Have a look at the actual field info for it as it is a reference field.
Collections (collections)
Description: The collections the product belongs to.
Type: Reference (Multiple Items)
Can connect to data: No
Can use in dynamic page URL: No
Can be sorted: No
Can be filtered: hasSome
Read-only: Yes
So you would need to use the hasSome data query function in your code as shown in the Wix API Reference here.
See pages for more info on this reference field.
You can see this example here for how to use it.
You might just want to use the Wix Stores Collections instead of Products and use the id field.
https://support.wix.com/en/article/corvid-wix-stores-collections-collection-fields
ID (_id)
Description: The collection ID that was created by the server. This is a system field and is hidden by default. This information also appears in the Products collection in a hidden field called “collections.id”. You can copy the ID from here and then use it to query the Products collection by the collection ID.
Type: Text
Can connect to data: Yes
Can use in dynamic page URL: Yes
Read-only: Yes
Hello, I would like to point out that the question has not yet been answered - because in contrast to the documentation
the attribute collections is not included in the API response (but in the Content Manager table, for example). What needs to be done to get this attribute?
Just to be completed:
wixData.query("Stores/Products")
.find()
.then((results) => {
if(results.items.length > 0) {
console.log(results.items[0]);
} else {
// handle case where no matching items found
}
})
.catch( (err) => {
let errorMsg = err;
});
Thank you and greetings
Lynn