Flutter firestore - Check if document ID already exists

前端 未结 4 1712
终归单人心
终归单人心 2020-12-02 01:48

I want to add data into the firestore database if the document ID doesn\'t already exists. What I\'ve tried so far:

// varuId == the ID that is set to the do         


        
4条回答
  •  北海茫月
    2020-12-02 02:25

    To check if document exists in firestore. Trick use .exists method

    Firestore.instance.document('collection/$docId').get().then((onValue){
    onValue.exists ? //exists : //not exist ;
    });
    

提交回复
热议问题