title: Firebase add to if data does not exist
body: <p>first time asker, so here it goes. I'm trying to write some Java for Android and Firebase where I need to check if an event record exists, and then adding it to a child if it does not exist. I currently am using one node for storing specific details on events, and the other node for just the city information. </p>
  
  <p>This is what my database looks like: </p>
  
  <pre><code>App: {
    Details: {
         eventName: Name
         eventType: Type
         eventCity: Location
         etc, etc...
    }
  
   OnlyCities: {
  
   }
  </code></pre>
  
  <p>This is to check and add only new entries to OnlyCities list:</p>
  
  <pre><code>appRef.addChildEventListener(new ChildEventListener() {
          @Override
          public void onChildAdded(DataSnapshot dataSnapshot, String s) {
              onlyCitiesRef.addValueEventListener(new ValueEventListener() {
                  @Override
                  public void onDataChange(DataSnapshot dataSnapshot) {
                      for (DataSnapshot data : dataSnapshot.getChildren()) {
                          if (!data.hasChild(eventCity)) {
                              onlyCitiesRef.push().setValue(eventCity);
                          }
  
                          else {
                              Toast.makeText(getApplicationContext(), "City already exists", Toast.LENGTH_SHORT).show();
                          }
                      }
                  }
  
                  @Override
                  public void onCancelled(DatabaseError databaseError) {
  
                  }
              });
          }
  </code></pre>
  
  <p>My problem is that I cannot check OnlyCities to see if something exists in there because the trigger for EventListener is onDataChange, and if I won't add data without checking, then there will never be a "data change"! </p>
  
  <p>Can someone give me some guidance on how to get around this? Is there any way to get a datasnapshot without having to fire a listener?</p>