I want to add a new map in array named players
but everytime i try to add it with this code
await setDoc(
doc(firestore, 'gambles', gambleId),
{
players: arrayUnion({
balanceDrop: silver,
id: userId,
login: userData.login
}),
totalPlayers: increment(1),
totalSilver: Number(gambleData?.totalSilver) + Number(silver)
},
{ merge: true }
);
and there is already a map with same values another map is not being created only totalSilver
and totalPlayers
values are being updated I just want another map even if values are the same
2
Answers
try the following.
let me know any?
arrayUnion
is behaving exactly as it’s supposed to here. It will not add new array elements that are the same as any existing elements. That’s why it’s called a "union" operation as opposed to a "push" operation. This is made clear in the documentation:If you want to add a duplicate element, you have to first read the document, modify the array in memory to contain whatever duplicates you want, then update the array field back to the document.