I have already two images in the firestore database, I am trying to add a new image to this list? How can I add a new image to the existing image list?
Advertisement
Answer
To add another array to the postImg
, you can:
JavaScript
x
7
1
const db = firebase.firestore();
2
const colRef = db.collection("user@domain.com");
3
const docRef = colRef.doc("1fJBcGT8DlZdgbl01LeX");
4
docRef.update({
5
postImg: firebase.firestore.FieldValue.arrayUnion("thenewurl");
6
})
7
Also see the Firebase documentation on adding items to an array.