There are many similar questions like this, this, and this.
However, none of the solutions worked.
How can you increment a nested Firebase property with the FieldValue.increment
function?
This code doesn't have any effect.
// Set query.
let query = firebase.firestore()
.collection('foobar')
.where('id', '==', userId);
// Run query.
try {
const querySnapshot = await query.get();
return querySnapshot.docs[0].ref.update({
[`test.${serviceId}.amount`]: firebase.firestore().FieldValue.increment(1)
});
} catch(e) {
console.log('Error: ', e);
}