issue:
The code adds JobNum from Jobs collection, as long as it is unique as jobId in Images collection.
Somehow, I get duplicates!
I know this code is simple, but something is wrong.
The line if (length === 0) is always true.
Hi, The collections types are fine . If I put some items in the collection, the length is not 0.
The issue is a sync issue.
It iccures when the query happens before the insert, and this is why the length is 0.
Both compared fields are ‘Text’ type, and the values from Jobs/jobNum is the one that inserted to Images/jobId only by this function, so they must be the same.
Thanks anyway:)
Dafna
I just want to see you data structure to better understand your problem. If there is a sync issue you need to share the insert code as well. you can have a look at collection hooks maybe that would help
The duplicates are in the Jobs collection, and it’s ok.
When running with this function, I wish to have the Images/jobId unique.
I wrote data code hundreds times.
Not sure what I’m missing here
Hi Dafna,
You have promises and async/await mixed in your code which can result in unexpected behavior like you’re experiencing.
I suggest to read https://support.wix.com/en/article/corvid-working-with-promises once again, choose a way you want to use and stick with it.
Your code looks very complicated (beyond my comprehension)
But why did you leave all the “catch” there?
also, instead of if (json[i].lists[0] !== undefined you should probably write
@jonatandor35 Hi, The ‘catch’ is for handling error cases.
undefined is when the field is undefined (length=0, but the length can not be measured, since the field is undefined).
“undefined” is a string with the value “undefinend” (length=9).
@dafna-kotzer I know what “catch” and “undefined” are. But I think you used them incorrectly.
You put a “catch” in an async function (even though it’s not a promise and I think you can’t do it). And when the variable is not assigned to any value, you need to use: if(typeof stringX === “undefined”) typeof checks for the type of the variable value, and it is “udefined” if it’s empty.
if it is a string with length zero, then you need if(stringX === “”)