问题
I have this simple struct:
{
"items": {
"item1": {
"likes": 4
},
"item2": {
"likes": 5
}
}
}
I enable offline mode:
Firebase.getDefaultConfig().setPersistenceEnabled(true);
Multiple users can increase the "likes" fields at the same time. How can I increase the likes filed by 1 in offline mode? If I get the likes value than set it with the increased value, what happens it the device reaches the server but another users before that have increased the same likes field? Will it overwite the value?
I can imagine my data structure is not so good because I'm new to NoSQL. I can add Firebase userids to the likes fields instead of a counter integer and summarize them to get the result. But this means lots of unneccessary data beacuse I don't need to know who liked I just need the number of likes.
Please help me to find out the best solution! Thank you!
来源:https://stackoverflow.com/questions/45276327/how-to-increase-a-value-in-firebase-realtime-database