Inserting values in a live collection doesn't work while in test it does

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

Have you synced your sandbox to your live for your datasets?

Remember in the Wix preview emulator that you are working in the sandbox version, whilst your users are working with the live published version.

Thank you for your reply. As this is a backend function, everything goes live automatically without the need of scync. My problem is more that the wixData.insert is not inserting on the live collection, while the preview one does have it.

@jhonychu93

As with Wix Data insert.
https://www.wix.com/corvid/reference/wix-data.html#insert

Have you looked at Wix Data WixDataOptions?
https://www.wix.com/corvid/reference/wix-data.html#WixDataOptions

@givemeawhisky

Thanks again.

Yes, I have tried options already and nothing :frowning:

Regarding wixData.insert is what I am using. Like I mentioned before, it works well with fetch, but doesn’t work with wixData.query.

Any other ideas?

Any Moderator? Please help, I have been stuck for many days.