I have a app chat based on firebase database and I want to know if a particular value is already stored.
According to the above structure how can I prevent two equal values (in red) from being inserted into the same child (blue)?
EDIT
I solved this problem as follows: 1) I changed the push values of each node by unique username; 2) I checked the duplicate values with the code below:
FirebaseDatabase.getInstance().getReference().child("friend").child(value_in_blue)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(!dataSnapshot.hasChild(username)) {
//value does not exists
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Thank you Frank van Puffelen and Jins Lukose for giving me guidance on this issue.