I have a comments screen with a list of comments and a textbox at the bottom. I have two ways of saving the comment with the updated comments count:
1) Using set()
ref.child(commentsList).child(commentKey).set(true);
ref.child(commentsCount).set(++count);
2) Using update()
allCommentKeysArray[newCommentsKey] == true
var data = {
commentscount: ++count,
commentslist: { ...allCommentKeysArray}
}
ref.child(path).update(data);
Now, for the offline situation, that is when the client gets disconnected from the internet, if I add multiple comments while being offline, here is what happens in both cases:
The set() works fine. All the comments which user added while being offline gets saved to firebase database when the client is back to online mode.
But update() does not seem to work when offline. When client return to online mode, the 'counts' values is not correct and only one key is added to 'commentsList' node in the firebase database.
I want to use update() instead of set() but update() does not seem to work for offline mode. So, should I stick with the set() as I need to achieve offline functionality, or is there any better way?