qqrrrr
qqrrrr

Reputation: 585

How to remove a specific child in Firebase (Android)

Instead of setting the data to null from the child of table Driver.. I want that specific child to be removed.

Here is my sample code.

driverRef = new Firebase(Config.FIREBASE_URL_DRIVER);
                    Query pendingBus = driverRef.orderByChild("busNum").equalTo(busNum);
                    pendingBus.addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                                String busnumber = snapshot.child("busNum").getValue().toString();
                                String empID = snapshot.child("empId").getValue().toString();

                                if (busnumber.equals(busNum)) {

                                    snapshot.getRef().child("age").setValue("");
                                    snapshot.getRef().child("busNum").setValue("");
                                    snapshot.getRef().child("driversName").setValue("");
                                    snapshot.getRef().child("empId").setValue("");
                                    snapshot.getRef().child("latitude").setValue("");
                                    snapshot.getRef().child("longitude").setValue("");
                                    snapshot.getRef().child("password").setValue("");
                                    snapshot.getRef().child("username").setValue("");
}
}

and this is the output of that method setValue Output

Upvotes: 1

Views: 5792

Answers (2)

saigopi.me
saigopi.me

Reputation: 14908

this is worked for me

databaseReference = databaseReference.child("Users").child(mobile);
databaseReference.setValue(null);

Upvotes: 0

qqrrrr
qqrrrr

Reputation: 585

Instead of using setValue to null I use .removeValue Example: snapshot.getRef().child("age").removeValue();

Upvotes: 3

Related Questions