0

I have some body data coming into firebase functions as a array ['123','hello','34']

I then process it by doing const data = JSON.stringify(['123','hello','34'])

After i update the firestore data by doing a set

set({testData : firestore.FieldValue.arrayUnion(data)})

Problem is, the entire thing is saved as string in firestore

testData: "['123','hello','34']"

Instead of an array.

testData: 
 0: "123"
 1: "hello"
 2: "34"

My question is how do i get firestore to save it as an array?

1 Answer 1

1

You are converting it to a string by using stringify(). Try refactoring the code as shown below:

docRef.set({ testData : firestore.FieldValue.arrayUnion(...data) })
// use spread operator here                             ^^^

The documentation (NodeJS) has an example on adding multiple values using arrayUnion.

Sign up to request clarification or add additional context in comments.

1 Comment

Nice, so i didn't need to do any conversions, thanks heaps !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.