I want to store one value(VarCount) in the database. The user will submit his count and i will add it to the VarCount in the database. Iam currently using firebasedb. But when multiple users simultaneously update it, it is working correctly. only one value is getting updated. what should i do? which is a better option for me? i have only one variable in the database that needs to be used and updated by the users. should i use firebasedb or a clouddb or a tinywebdb? Please help me out.
Thanks.
For the majority of databases, they will allow some kind of lock to prevent data crashes as you describe, and either prevent the “second” simultaneous update, or wait and then apply it. This may happen so fast that you can’t see it - and therefore you will only see one update (even though there were two or more)
Alternately, you could store all update values as separate fields, then display the last…
I used firebaseDB. say varCount=3 in the database
user1 submits : 2 and at the same time,
user2 submits : 1.
My code is to add to varCount what ever the user submits.
so it should be varCount = 3 + 2 + 1 = 6
What is happening is, varCount= 3+ 2 =5 (user2 value is totally lost).
Firebase can handle simultaneous updates (see documentation ) by using the update method. The experimental (and deprecated) FirebaseDB control does not have a similar method Block. I believe you are out of luck.
The CloudDB also does not have an update method.
Consider Tim’s advice.
Alternatively, consider using one of the not free databases that use an api and have more flexibility.
ok. how about tinywebDB? will that solve my problem?
Probably not. See
for what methods are available.
For the TinyWebDB, consider the documentation Although this component is usable, it is very limited and meant primarily as a demonstration for people who would like to create their own components that talk to the Web
I am surprised you are getting a data loss. How are you testing with your two users, two separate devices? it should only take a few milliseconds difference to receive both values…
You might be able to solve your dilema using VarCount as a List instead of as a variable. You could then use
to capture all submittals. You might compare the List of items (if you submit the items as a List of pairs that should be date stamped) . The List might capture all updates. With that information you might get your app to do what it needs to do.
You did not share your code blocks or tell us whether you are creating a real time game or what. It certainly makes a difference.
seems a likely situation and would seem to preclude collisions. The issue might be that Firebase is a 'real time' database and there is not instantaneous communication and response to any submital of data. The Internet is so fast, we sometimes forget that.
Tim… Yes iam using two seperate mobiles and hitting on submit button at the same time. Iam logging the details in a Google sheet. The time stamp is the same hr,same min and same sec. So there is a difference of mili seconds.
I recently discussed this problem in this thread ...
I posted a way to avoid count loss most of the time, and discussed a way to allow users to monitored whether or not their vote counted or not.
Thanks… I will take a look. Iam actually keeping track of all the submissions in Google sheets. I was thinking, I can keep one cell in Google sheets that give the total count. Will Google sheets solve multiple user problem?