I know that there are similar thread names in the forum, but none of them have the same problem as I am currently facing as I have already tried the other solutions with permissions matters.
Other things like beforeInsert() has also been tried, but still nothing comes up. The problem is that I am trying to insert an array in a collection and this is not happening in live collection. This function is a wixData.query, which is inside of a GET fetch function .
It is also important to mention that when I insert this array in a collection within the fetch function, everything is OK, but when I do it within the wixData.query, it doesn’t.
The goal is to append images’ URL from another collection (cityImages) to every API observation/row (city), which is an array that is inserted into a new collection (categoryCollection). For your reference, I have already tried reference fields and this does not apply to this particular case.
This is the code:
fetch(url, {method: 'get'},options)
.then(response => response.json())
.then((response) => {
for (var i=0;i<10;i++) {
//response['data'].length
const resultArray = {
"countryFrom": response['data'][i]['countryFrom'].name,
"iataCountryFrom": response['data'][i]['countryFrom'].code,
"countryTo": response['data'][i]['countryTo'].name,
"iataCountryTo": response['data'][i]['countryTo'].code}
// THIS IS INSERTED CORRECTLY
wixData.insert("myCollection", resultArray)
.then( (results) => {
let item = results;})
.catch ((err)=> {
let errorMsg = err;
console.log("categoryArray appended");
});}
for (var h=0;h<1;h++) {
let categoryArray = {
"countryName6": response['data'][h]['countryFrom'].name,
"iataCountry6": response['data'][h]['countryFrom'].code,
"flyFrom3": response['data'][h]['cityFrom'],
"iataFrom": response['data'][h]['flyFrom'],
"flyTo3": response['data'][h]['cityTo']
}
wixData.query("cityImages",options).eq('city', response['data'][h]['cityTo']).find()
.then(results5 => { return results5.items[0].image})
.then(res => {let bcd = {"image6": res}
let finalArray = Object.assign({}, categoryArray,bcd)
// THIS DOESN'T WORK AT ALL
wixData.insert("categoryCollection", finalArray)
})
// THIS IS AN EXAMPLE OF WHAT ALSO WORKS
wixData.insert("categoryCollection", categoryArray)
I hope someone has a solution. Thank you in advance.
Regards,
Jhony