【问题标题】:Failed assertion while trying to get single document from firebase尝试从 firebase 获取单个文档时断言失败
【发布时间】:2020-07-09 20:22:30
【问题描述】:

我只是想从我的 firebase 集合中获取一个文档
但我收到此错误:未处理的异常:PlatformException(错误 5,FIRFirestoreErrorDomain,没有要更新的文档
我有一个带有文档 ID 的文档,我通过打印检查了它
这是我的代码:

  void updateBalanceOfSender() async {
    var docID;
    Firestore.instance
        .collection('balance')
        .where('user', isEqualTo: loggedInUser.email)
        .snapshots()
        .listen((data) =>
            data.documents.forEach((doc) => print(docID = doc.documentID)));
    _firestore
        .collection('balance')
        .document(docID)
        .updateData({'balance': '1'});
  }

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    您将错误的参数传递给 where 方法。 使用下面的代码:

     void updateBalanceOfSender() async {   
    
        var document = await Firestore.instance      
        .collection('balance')      
        .where(“user”,isEqualTo: loggedInUser.email);
    
        print(document);
    
    }
    

    查看this 了解如何执行查询。

    This question 也可能有帮助。

    【讨论】:

    • 实际上我想通过 document.documentID 获取文档ID,但是在我按照您所说的那样修复代码之后,我得到了这个错误;无效参数:“CupertinoDatePickerMode”的实例
    • 我在您的代码中没有看到 DatePicker。请更新您针对此错误发布的代码,但从我从您的问题和您收到的错误中可以看出,我的代码必须解决问题。 where 方法将返回用户字段已登录InUser.email 值的文档,您可以通过 document.id 获取 id
    • *可以通过document.documentID获取文档id
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    相关资源
    最近更新 更多