How to delete from firebase realtime database?

后端 未结 5 1557
一个人的身影
一个人的身影 2020-11-30 00:58

I am using Firebase realtime database in Android app, and have data like this:

How can i delete the record \"Apple\" (marked in picture)?

A

相关标签:
5条回答
  • 2020-11-30 01:36

    You can use this code :

    onDeletePost(id:string){
    return this.http.delete(`https://my-angular8-prjt.firebaseio.com/posts/${id}.json`).subscribe();
    }
    
    0 讨论(0)
  • 2020-11-30 01:39

    If you are using firebase-admin you can simply try this out as

    admin.ref(`/users/${userid}`).remove()
    

    and that works for me.

    And also do remember to use async and await syntax.

    0 讨论(0)
  • 2020-11-30 01:42

    this solved my problem

     mPostReference = FirebaseDatabase.getInstance().getReference()
                            .child("quotes").child(mPostKey);
                    mPostReference.removeValue();
    
    0 讨论(0)
  • 2020-11-30 01:46

    Depending on how and why you are deleting the data you can use these:

    // Could store the push key or get it after push
    String newPostKey = yourDatabase.child('firebase-test').push({
        something:something
    }).key();
    
    // Depends how you get to here
    howYouGotHereId.parent().setValue(null);
    

    Firebase Save Data 3.0

    0 讨论(0)
  • 2020-11-30 01:47

    If you don't know the key of the items to remove, you will first need to query the database to determine those keys:

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
    Query applesQuery = ref.child("firebase-test").orderByChild("title").equalTo("Apple");
    
    applesQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot appleSnapshot: dataSnapshot.getChildren()) {
                appleSnapshot.getRef().removeValue();
            }
        }
    
        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e(TAG, "onCancelled", databaseError.toException());
        }
    });
    
    0 讨论(0)
提交回复
热议问题