I'm trying to use firebase database transactions to update a "likes" counter in my database. But when running the transaction, mutable data returns null even though the node clearly exists. Here is my code.
FirebaseDatabase.getInstance().getReference("uploads").child(id)
.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData mutableData) {
Post p = new Post();
if (mutableData.getValue(Post.class) != null) {
p = mutableData.getValue(Post.class);
} else Log.w("mutableData", "isEmpty");
p.setLikes(p.getPoints() + 1);
// Some other code...
I'm not sure why it's returning null. The id
clearly exists under the uploads
node. What could possibly be the problem and what can I do to solve it?