Hey everyone
I was trying to copy the ‘collections’ from Wix Stores databases to another collection, trying to get the ID of the collection returns an empty value (null).
The second collection has a reference field to the (Stores/Collections) collection, and an id that I might need in the future, and since the main field is the name of the collection, I used it to assign the referenced value.
collection: item.name
Enough chit chat, here’s the code:
await wixData.query('Stores/Collections').limit(100).find(options).then(async (collection) => {
let allItems = collection.items
let length = collection.totalCount
let i
while (collection.hasNext()) {
collection = await collection.next();
allItems = allItems.concat(collection.items);
console.log(allItems.length, 'retrieved')
}
console.log(allItems)
console.log('Start copying..')
for (i = 0; i < length; i++) {
let item = allItems[i];
let newItem = {
id: item._id,
name: item.name,
collection: item.name,
mainMedia: item.mainMedia
}
await wixData.insert('NewCollection', item).then(() => {
console.log(`Item ${i} copied`)
})
}
})
}
Also, getting the _id of the collection failed! I even tried it from the Backend but without any luck.
Is it a limitation on the collection itself, or it’s just me who’s missing something ?
Help is appreciated.