【问题标题】:Check if string already exists in a field in cloudfirestore field and flutter检查字符串是否已存在于云 Firestore 字段中的字段中并颤动
【发布时间】:2018-08-07 20:42:50
【问题描述】:

我在cloudfirestore中有一个名为IDS的集合,里面有一个名为IDs的文档,在这个文档中我有以ID1开头的字段几乎达到ID14000,用户在文本字段中输入他的ID,我需要检查是否id 存在于字段中,谢谢。

【问题讨论】:

    标签: dart google-cloud-firestore flutter


    【解决方案1】:
    final CollectionReference dbIDS = Firestore.instance.collection('IDS');
    
    QuerySnapshot _query = await dbIDS
        .where('ID', isEqualTo: theUserInputID)
        .getDocuments();
    
    if (_query.documents.length > 0) {
      // the ID exists
    }
    

    【讨论】:

    • 我的字段有不同的名称。并非所有人都是 ID,我有 ID1、ID2、ID3、ID4 .....如果是这种情况,您的代码会起作用
    • 无论字段名称是什么,都只需设置“ID”即可。并将 isEqualTo 更改为检查任何值的东西。
    猜你喜欢
    • 2018-12-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2013-07-23
    • 2012-05-09
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多