【问题标题】:search firebase document for a specific field in flutter dart and store it在flutter dart中搜索特定字段的firebase文档并将其存储
【发布时间】:2021-11-05 11:49:02
【问题描述】:

我正在尝试恢复其字段“电子邮件”等于某个值的文档我的代码没有得到任何东西不知道是什么问题

 void EditDisplayedName(String email, String name) async {
  CollectionReference s = FirebaseFirestore.instance
      .collection("Users")
      .doc("list_instructors")
      .collection("Instructor")
    ..where("Email", isEqualTo: email);

  s.doc(email).update({'Full Name': name});
} //end method

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore


    【解决方案1】:

    您的代码尚未找到/读取电子邮件地址的文档。

    正确的流程是:

    // 1. Create a reference to the collection
    CollectionReference s = FirebaseFirestore.instance
        .collection("Users")
        .doc("list_instructors")
        .collection("Instructor")
    
    // 2. Create a query for the user with the given email address
    Query query = s.where("Email", isEqualTo: email);
    
    // 3. Execute the query to get the documents
    QuerySnapshot querySnapshot = await query.get();
    
    // 4. Loop over the resulting document(s), since there may be multiple
    querySnapshot.docs.forEach((doc) {
    
      // 5. Update the 'Full Name' field in this document
      doc.reference.update({'Full Name': name});
    });
    
    

    【讨论】:

      猜你喜欢
      • 2020-12-01
      • 2020-09-20
      • 2021-07-04
      • 2022-12-10
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      • 1970-01-01
      • 2022-12-20
      相关资源
      最近更新 更多