I have the below code which at first run creates a new collection with a document ID that is equal to my UID. This newly created document has an array named 'array' which contains the cocktailInformation object. So far all works fine.
const saveData = (uid) => {
db
.collection('users')
.doc(uid)
.set({
array: [ cocktailInformation ]
})
.then(function() {
console.log('Document successfully written!');
})
.catch(function(error) {
console.error('Error writing document: ', error);
});
};
the issue arises when i want to add more objects to this array in this document. I checked firestore docs on how to do this and it shows the below
var washingtonRef = db.collection("cities").doc("DC");
// Atomically add a new region to the "regions" array field.
washingtonRef.update({
regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
});
// Atomically remove a region from the "regions" array field.
washingtonRef.update({
regions: firebase.firestore.FieldValue.arrayRemove("east_coast")
});
but i don't know how to integrate this as the current code only updates the current object with the one i send off to firestore. Can anyone give me some tips? BTW this is a react app
dbin your code?