Check if Field Already exists in Flutter Firestore

前端 未结 4 1921
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  萌比男神i
    2020-12-15 01:07

    final QuerySnapshot result =
        await Firestore.instance.collection('users').where('nickname', isEqualTo: 
        nickname).getDocuments();
    
    final List < DocumentSnapshot > documents = result.documents;
    
    if (documents.length > 0) { 
    
      //exists
    
    } else {  
    
      //not exists
    
    }
    

提交回复
热议问题