So I’m working on a personnal project to learn react-native and firestore.
and I want by code to add a new battery in the array batteries
.
The elements in the array are just a map{string, string}
The problem is that when I update the array with a new brand that’s work but if I want to update it with the same brand again have,
so having by the end
batteries[0]: {'brand': 'cestmoi'}
batteries[1]: {'brand': 'cestmoi'}
the db doesn’t update, don’t have any error or so.
I don’t understand why and I followed their tuto. Here is my code:
async function addData(collection, doc, value) {
console.log(`Add data ${value.brand}`)
try {
const result = await firestore()
.collection(collection)
.doc(doc)
.set({
batteries: firestore.FieldValue.arrayUnion(value)
})
console.log(result);
return result;
} catch (error) {
return error;
}
}
I use try catch by habit but I don’t know if the then...catch
is better or not…
Thanks