My cloud function is triggered when a specific event occurs. Within the function, I receive an array of strings like this example:
let h:string[] = ["foo","bar","baz"]
. When I attempt to update an array field within my document using
names: admin.firestore.FieldValue.arrayUnion(h)
, it fails and throws the following error in the console:
Error: 3 INVALID_ARGUMENT: Cannot convert an array value in an array value.
at Object.exports.createStatusError (/srv/node_modules/grpc/src/common.js:87:15)
at Object.onReceiveStatus (/srv/node_modules/grpc/src/client_interceptors.js:1188:28)
at InterceptingListener._callNext (/srv/node_modules/grpc/src/client_interceptors.js:564:42)
at InterceptingListener.onReceiveStatus (/srv/node_modules/grpc/src/client_interceptors.js:614:8)
at callback (/srv/node_modules/grpc/src/client_interceptors.js:841:24)
However, if I change the code to:
names: admin.firestore.FieldValue.arrayUnion("foo","bar","baz")
, it works. But since my function receives an array, not the above format, it fails.
What I need is to have an array field in the document called 'names'. When the function is triggered and I receive the array from it, I want to add this array to the existing names array.
Before adding the array: names : ["test","test2"]
After adding the array:
names : ["test","test2","foo","bar","baz"]
How can I fix this issue? I am using typescript 3.0.1