I have a list [a,d,f]. I want to increment those fields in the test map respectively.
If I were to hard code it, it'll look something like this.
firestore.collection('x').doc('y').update({
'test.a':FieldValue.increment(1),
'test.d':FieldValue.increment(1),
'test.f':FieldValue.increment(1),
});
But what if the list always changes. How can increment the map according to the list every time? Any suggestion would be appreciated!
You can try creating a map from that list:
var myList = ["a", "d"];
var myMap = { for (var item in myList) 'test.$item': FieldValue.increment(1) };
print(myMap);
// {test.a: FieldValue.increment(1), test.d: FieldValue.increment(1)}
firestore.collection('x').doc('y').update(myMap)