Here is the code.The update not works and the count is still 0 after update.
FirebaseFirestore store = FirebaseFirestore.DefaultInstance;
CollectionReference globalRef = store.Collection("global");
DocumentReference doc = globalRef.Document("rank"+rankType);
store.RunTransactionAsync((transaction) =>
{
return transaction.GetSnapshotAsync(doc).ContinueWith((task) =>
{
if (task.Result.Exists)
{
int rank = 1;
int count = 0;
long t = 0;
Dictionary<string, object> dic = task.Result.ToDictionary();
rank = int.Parse(((Dictionary<string, object>)dic["data"])["rank"].ToString());
count = int.Parse(((Dictionary<string, object>)dic["data"])["count"].ToString());
t = long.Parse(((Dictionary<string, object>)dic["data"])["timestamp"].ToString());
if (count >= 200 && timestamp > t)
{
transaction.Update(doc, "rank", rank + 1);
transaction.Update(doc, "count", 0);
transaction.Update(doc, "timestamp", timestamp + 3600);
}
else
{
transaction.Update(doc, "count", count + 1);
}
}
});
});
I want to increase the count and when the count reaches 200 the rank should be increased and reset the count to 0.