Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

java - I want to delete the array stored in Firestore

I received the user's email and designated it as the name of the document, and stored the user information in the document in an array. I tried running my code, but only the Toast message is executed, not deleted.

I have listed the arrays as a list using RecyclerView. Deletion will be implemented through showPop() method.

This is my Firestore database enter image description here I want to delete index-0

  private void showPopup(View v,final int position) {  

  PopupMenu popup = new PopupMenu(activity, v);
  popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                switch (menuItem.getItemId()) {
                    .....
                    case R.id.delete: //delete
                        final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                        final FirebaseFirestore db = FirebaseFirestore.getInstance();
                        final Map<String, Object> updates = new HashMap<>();
                        updates.put(user.getEmail(),FieldValue.delete());

                        //db.collection("medicinday").document(mDataset.get(position).getId())
                          //      .delete()
                        db.collection("medicinday").document(user.getEmail()).update("add_day", FieldValue.arrayRemove(user.getEmail()))
                                .addOnSuccessListener(new OnSuccessListener<Void>() {
                                    @Override
                                    public void onSuccess(Void aVoid) {
                                        Toast.makeText(....
                                    }
                                })
                                .addOnFailureListener(new OnFailureListener() {
                                    @Override
                                    public void onFailure(@NonNull Exception e) {
                                 ....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...