title: Check if firebase child has a specific value
body: <p>I have a app chat based on firebase database and I want to know if a particular value is already stored. </p>
  
  <p><a href="https://i.stack.imgur.com/Q5GDS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q5GDS.png" alt="Database structure"></a></p>
  
  <p>According to the above structure how can I prevent two equal values ​​(in red) from being inserted into the same child (blue)?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>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:</p>
  
  <pre><code>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) {
              }
          });
  </code></pre>
  
  <p>Thank you  Frank van Puffelen and Jins Lukose for giving me guidance on this issue.</p>