Let's go through what is happening. You have two lists of equal size (4 elements): datasourcefieldname and sourcedatabasename. In your code, you unwind datasourcefieldname first. What the unwind does is create a row of data for each element in the list your are unwinding. All the other data at the time gets appended to the row. The result of the first unwind is shown in the screenshot. As you can see, you get four rows, one row for each value of datasourcefieldname. Also shown is that the sourcedatabasename list is repeated for each row.
After the second unwind on sourcedatabasename, you will get the result shown in the following screenshot. As you can see, for each of the four rows above, the unwinding of sourcedatabasename creates four rows each, one row for each element in the sourcedatabasename list. We now have 16 rows, resulting from the 4 rows from datasourcefieldname and 4 rows from sourcedatabasename.
with ['field1', 'field2','field3','field4'] as datasourcefieldname, ['database1','database2','database1','database2'] as sourcedatabasename
unwind datasourcefieldname as d
unwind sourcedatabasename as s
return *
In your code, you use the value of datasourcefieldname from the first unwind to filter for the node represented by 'dsfv' (using the 'where' clause). That node is either matched to 'field1', 'field2', 'field3', or 'field4'. For each of these values, the second unwind results in four rows each, iterating over 'database1', 'database2', 'database1', and 'database2'; therefore, the 'SET' clause on the last line is executed four times for 'field1', four times for 'field2', etc. The final value of 'dsfv.SourceDatabase' will be the last value set, since the prior three will have been overwritten by the last one. The last element in the 'sourcedatabasename' list is 'database2'.
As you can see, a double unwind does not work in your scenario. What you really want is to process the first element of the datasourcefieldname list with the first element of the sourcedatabasename list, and the second with the second, etc. I accomplished this by creating a list of four integers ([0,1,2,3]) using the 'range' function and unwinding the integer list. This gives the following result, were we have four rows, one for each index value. The datasourcefieldname and sourcedatabasename lists are repeated on each row.
I can now process each corresponding element from both lists on each row by using the value of 'index' to extract each from their list. You can see this when I add datasourcefieldname[index] and sourcedatabasename[index] to the output. These values can now be used to perform the matches to get the correct nodes and create the relationship between them.
It would be a different problem if the sizes of the two lists were different. In your case the first list represented the node to find and the second list represent a property value to set on the node from the first list. The solution would depend on what you are trying to accomplish.