FirebaseException ([cloud_firestore/not-found] Some requested document was not found.)

huangapple go评论60阅读模式
英文:

FirebaseException ([cloud_firestore/not-found] Some requested document was not found.)

问题

onConfirm: (date) async {
  await FirebaseFirestore.instance.collection('orders')
    .doc(order['orderid']).update(
     {
       'deliverystatus': 'shipping',
       'deliverydate': date,
     }
  );
}
英文:
onConfirm: (date)async{
  await FirebaseFirestore.instance.collection('orders')
    .doc(order['orderid']).update(
     {
       'deliverystatus':'shipping',
       'deliverydate':date,
    }, 
  );
}

FireBase screenshot

FirebaseException ([cloud_firestore/not-found] Some requested document was not found.)

答案1

得分: 0

您正在尝试通过文档ID加载文档,但在您分享的截图中,orderid 字段的值 (250fa...) 与中间列中的文档ID (CwdHE...) 不匹配

如果您知道文档ID,您可以将其传递给 doc() 方法,然后保持您的其余代码不变。

如果您不知道文档ID,您可以使用查询根据其 orderid 查找文档。根据该链接中的示例代码,它看起来像是这样的:

db.collection("orders").where("orderid", isEqualTo: order['orderid']).get().then(
      (querySnapshot) {
        print("成功完成");
        for (var docSnapshot in querySnapshot.docs) {
          print('${docSnapshot.id} => ${docSnapshot.data()}');
        }
      },
      onError: (e) => print("完成时出错: $e"),
    );

但请考虑一下,是否真的需要不同的文档ID和订单ID。如果您的 orderid 值在 orders 集合中始终是唯一的,那么将 orderid 用作文档ID,或者使用Firestore生成的文档ID作为订单ID可能更容易。

英文:

You're trying to load the document by its document ID, but in the screenshot you share the value of the orderid field (250fa...) does not match the document ID (CwdHE...) in the middle column.

If you know the document ID, you can pass that to the doc() method instead, and keep the rest of your code the same.

If you don't know the document ID, you can use a query to loop up the document based on its orderid. Based on the sample code in that link, it'd look something like:

db.collection("orders").where("orderid", isEqualTo: order['orderid']).get().then(
      (querySnapshot) {
        print("Successfully completed");
        for (var docSnapshot in querySnapshot.docs) {
          print('${docSnapshot.id} => ${docSnapshot.data()}');
        }
      },
      onError: (e) => print("Error completing: $e"),
    );

Do consider though if you really need to have a different document ID and order ID. If your orderid values are always going to be unique in the orders collection, it might be easier to use the orderid as the document ID - or to use the document ID that Firestore generates as the order ID.

huangapple
  • 本文由 发表于 2023年5月7日 22:07:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76194433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定