In firestore, i have a collection called questions
of documents with the following structure
{ category : "animals",
topics : [ {title :"habitats", votes: 1}, {title :"pets", votes: 5} ] }
I want to build a function that receives title
as parameter, and increments votes
by one, with no success.
I am trying things like :
const docRef = doc(db, "questions", id);
await updateDoc(docRef, {
topics: {
name: topicName,
vote: increment(1),
},
});
//with arrayUnion
await updateDoc(docRef, {
topics: arrayUnion{
name: topicName,
vote: increment(1),
},
});
But the only thing I do is updating the array replacing the two objects with just a new one, or adding a new object to the two existing ones.