Check if Field Already exists in Flutter Firestore

前端 未结 4 1910
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 00:47

I have a collection called company. All the companies are going to be stored like in my screenshot.

When I add another company, I want

4条回答
  •  执笔经年
    2020-12-15 00:47

    I know I am late. Posting for future users. Try this:

    DocumentReference datab = db.collection("Company").document("Nova");
    
    
                        datab.get().addOnSuccessListener(new OnSuccessListener() {
                            @Override
                            public void onSuccess(DocumentSnapshot documentSnapshot) {
    
                                if(documentSnapshot.contains("name"))
                                {
                                    Toast.makeText(YourActivity.this, "Child exixts.", Toast.LENGTH_SHORT).show();
    
                                }
                                else
                                    Toast.makeText(YourActivity.this, "Doesnt exits.", Toast.LENGTH_SHORT).show();
    
    
                            }
                        });
    

提交回复
热议问题