'Array Union is not Defined in Firebase Firestore reactjs
I am trying to let my users upload multiple images at once. Now everything is working correctly, my only problem is that I am not getting the download Urls as an array in my firebase firestore document.
I am using the arrayUnion() functions to combine everything into an array but it gives me this error. "Unhandled Rejection (ReferenceError): arrayUnion is not defined"
What am i doing wrong?
Here is my code:
firebase
.firestore()
.collection("Properties")
.add({
propname: propName,
price: price,
bedrooms: bedroom,
bathroom: bathroom,
exclusive: exclusive,
area: area,
type: type,
category: category,
features: features,
services: services,
summary: summary,
// imageUrls: urls,
location: location,
salesAgentID: salesAgent,
date: getCurrentDate(),
})
.then(result => {
const promises = [];
Promise.all(
selectedImages.map(image => {
const storageRef = storage.ref(
`propertyImages/${result.id}/${image.name}`
);
storageRef.put(image).then(urls => {
storageRef.getDownloadURL().then(downloadUrls => {
console.log(downloadUrls);
firebase
.firestore()
.collection("Properties")
.doc(result.id)
.update({
propertyID: result.id,
images: arrayUnion(downloadUrls),//here is my problem
})
.then(res => {
//handleUploadChange();
alert("Property Added Successfully");
window.location.reload();
});
});
});
})
);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
