본문 바로가기
개발/Firebase

firebase function list에 list 더하기

by dev_caleb 2022. 12. 28.
728x90

https://stackoverflow.com/questions/52101685/firestore-failed-to-merge-array-of-items-to-another-array-using-fieldvalue-array

 

Firestore Failed to merge array of items to another array using FieldValue.arrayUnion()

I have a cloud function that invoked when a certain event happened. In the function i will get an array of string for example let h:string[] = ["foo","bar","baz"] something similar to this when I t...

stackoverflow.com

 

placeModel['tags'] = admin.firestore.FieldValue.arrayUnion(tags);}
placeModel["imageurls"] = admin.firestore.FieldValue.arrayUnion(matjipData["imageurls"]);
 

이렇게 하니까 오류가 났다.

Error: Element at index 0 is not a valid array element. Nested arrays are not supported. at validateArrayElement (/workspace/node_modules/@google-cloud/firestore/build/src/field-value.js:446:15) at ArrayUnionTransform.validate (/workspace/node_modules/@google-cloud/firestore/build/src/field-value.js:369:13) at /workspace/node_modules/@google-cloud/firestore/build/src/document.js:833:56 at Map.forEach (<anonymous>) at DocumentTransform.validate (/workspace/node_modules/@google-cloud/firestore/build/src/document.js:833:25) at WriteBatch.set (/workspace/node_modules/@google-cloud/firestore/build/src/write-batch.js:256:19) at DocumentReference.set (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:354:14) at /workspace/matjip_change.js:92:18 at processTicksAndRejections (node:internal/process/task_queues:96:5)

 

 

 

 

위의 글을 읽어보니 리스트를 추가하려면 이렇게 해야되나 보다.

 

placeModel['tags'] = admin.firestore.FieldValue.arrayUnion(...tags);
placeModel["imageurls"] = admin.firestore.FieldValue.arrayUnion(...matjipData["imageurls"]);

 

해보니 된다 성공!

728x90