{
"users": {
"-KKUmYgLYREWCnWeHCvO": {
"fName": "Peter",
"ID": "U1EL9SSUQ",
"username": "peter01"
},
"-BBUmYgLYREWCnWPDndk": {
"fName": "John",
"ID": "U1EL5623",
"username": "john.doe"
}
}
}
There is a possibility in my code where these 3 fields can get added again, with a different parent id For example, this can get added again, which I want to avoid
"fName": "Peter",
"ID": "U1EL9SSUQ",
"username": "peter01"
So how to check if all 3 fields under a unique parent id already exists?
mDatabaseUsers.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot data: dataSnapshot.getChildren()){
if (data.child("fName").exists() && data.child("ID").exists() &&
data.child("username").exists()) {
//do ur stuff
} else {
//do something
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
I tried the above code and it didnt work