Firebase is providing the following example for transactions in its guide :
function toggleStar(postRef, uid) {
postRef.transaction(function(post) {
if (post) {
if (post.stars && post.stars[uid]) {
post.starCount--;
post.stars[uid] = null;
} else {
post.starCount++;
if (!post.stars) {
post.stars = {};
}
post.stars[uid] = true;
}
}
return post;
});
}
So the object structure should look something like this:
posts
- postID
- starCount: Int
- stars
- uid : Bool
I was wondering if I could still perform transactions, when the object structure would look like this:
posts
- postID
- starCount: Int
postStars
- postID
- uid : Bool
So it wouldn't be necessary to load all the userIDs of the users who've stared the post when you load the data to display the post.