简体   繁体   中英

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 产量

我没有使用setValue作为null而是使用.removeValue示例: snapshot.getRef().child("age").removeValue();

this is worked for me

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM