【问题标题】:Firebase Cloud: Retrieve all values of the filed 'expireDate' from documentFirebase Cloud:从文档中检索归档“expireDate”的所有值
【发布时间】:2019-11-10 18:14:34
【问题描述】:

我正在尝试从属于当前用户的产品中检索“expireDate”中的值(用户引用了产品)。我正在使用 Flutter 和 Firebase Cloud - 数据库。

FirebaseUser user = await FirebaseAuth.instance.currentUser();
String product = 'exampleId';

    Firestore.instance
        .collection('users/${user.uid}/products')
        .snapshots()
        .listen((snapshot) {
      snapshot.documents.forEach((document) {
        print(document.data['idProduct'].path);
        print(document.data['idProduct']);
      });
    });

程序返回:'DocumentReference 的实例' 我预计'2020-05-02'

【问题讨论】:

    标签: android firebase flutter google-cloud-firestore


    【解决方案1】:

    加载具有DocumentReference 字段的文档不会自动加载链接的文档。您需要显式加载参考文档,然后查找您要查找的 expireDate 字段。

    类似

    Firestore.instance
        .collection('users/${user.uid}/products')
        .snapshots()
        .listen((snapshot) {
      snapshot.documents.forEach((document) {
        Document product = await document.data['idProduct'].get();
        print(product.data['expireDate']);
      });
    });
    

    【讨论】:

      猜你喜欢
      • 2019-01-25
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 2021-04-13
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多