title: Checking if a user already exists at firebase realtime database
body: <p>I get the <a href="https://stackoverflow.com/a/47893879/4176989">Alex Mamo's Solution</a> in order to check whether a unique value exists in my database but the snapshot gets always null. The solution is here:</p>
  
  <pre><code>DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
  DatabaseReference userNameRef = rootRef.child("Users").child("Nick123");
  ValueEventListener eventListener = new ValueEventListener() {
  @Override
  public void onDataChange(DataSnapshot dataSnapshot) {
      if(!dataSnapshot.exists()) {
          //create new user
      }
  }
  
      @Override
      public void onCancelled(DatabaseError databaseError) {}
  };
  userNameRef.addListenerForSingleValueEvent(eventListener);
  </code></pre>
  
  <p>And my database looks like this:</p>
  
  <pre><code>users
      (auto-generated push token ID)
          fullname
          username
          gender
          ...
  </code></pre>
  
  <p>I don't know whether it's the right method but I used push() method for adding the user object to the database and this method generates push token ID like above. </p>
  
  <p>So, in order not to create duplicate users, what should I change with the above solution? Is there a better method to do this? Maybe like checking the firebase uid with some firebase auth methods?</p>
  
  <p><strong>UPDATE</strong>
  My database screenshot:
  <a href="https://i.stack.imgur.com/zKUW8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zKUW8.png" alt="database"></a>
  As you see the string just below 'users' is not the same as user's uid. </p>