Reputation: 117
hello how to upload an array of images urls to firestore in react native i tried this
state = { photos: [] };
buttonPress() {
const { photos } = this.state;
firebase.firestore().collection('users').doc('images')
.add({ photos });
}
but the image would show like this in firestore database
{
"book": "Robin hood",
"photos": "https://picsum.photos/id/1001/5616/3744",
}
i would like it to instead show in an array like this in firestore database
{
"book": "Robin hood",
"photos": [ "https://picsum.photos/id/1001/5616/3744"],
}
Upvotes: 0
Views: 361
Reputation: 2290
This can be achieved by wrapping the photos
inside []
. Therefore your code would be;
firebase.firestore().collection('users').doc('images')
.add({ [photos] });
}
Also, incase you want the user to add later and not overwrite the array, I would suggest using set
with merge: true
.
firebase.firestore().collection('users').doc('images')
.set({ [photos] }, { merge: true });
}
Upvotes: 2