如何从我的Flutter应用程序向Cloud Firestore中填充乘客ID数组?

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

How can i populate my array of passengerIDs in cloud firestore from my flutter app

问题

我创建了一个乘客ID列表,但现在无法访问它们,以便在每次用户被接受乘坐时添加/更新乘客ID。

这是我的代码:

FirebaseFirestore.instance
    .collection("tripsStatus")
    .doc("${request.tripID}/passengerIDs")
    .update({"${int.parse(seat) - int.parse(data)}": request.userID});

以及我的Cloud Firestore路径

我尝试在用户请求加入乘坐时每次更新列表,但它不起作用,还给我一个错误:

java.lang.IllegalArgumentException: 无效的文档引用。文档引用必须具有偶数段,但tripsStatus/1686505092901977/passengerIDs有3段。

英文:

I created a list of passengerIDs but now I am not able to access them in order to add/update a passengerIDs everytime a user is accepted to a ride

Here is my code


    FirebaseFirestore.instance
        .collection("tripsStatus")
        .doc("${request.tripID}/passengerIDs")
        .update({"${int.parse(seat) - int.parse(data)}": request.userID});

And my cloud firestore path

I tried to update everytime the list when a user requested to join the ride but it's not working it also gives me the error
> java.lang.IllegalArgumentException: Invalid document reference. Document references must have an even number of segments, but tripsStatus/1686505092901977/passengerIDs has 3

答案1

得分: 1

你的错误意味着你没有更新一个文档,你需要提供你想要编辑/更新的文档ID。

FirebaseFirestore.instance
        .collection("tripsStatus")
        .doc("${request.tripID}/passengerIDs/${myDocumentID}") // 在这里添加你的文档ID
        .update({"${int.parse(seat) - int.parse(data)}": request.userID});
英文:

Your error means that you're not updating a document, you need to provide the documentID you want to edit/update.

FirebaseFirestore.instance
        .collection("tripsStatus")
        .doc("${request.tripID}/passengerIDs/${myDocumentID}") // you should add your document ID here 
        .update({"${int.parse(seat) - int.parse(data)}": request.userID});

huangapple
  • 本文由 发表于 2023年6月12日 18:51:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455921.html
匿名

发表评论

匿名网友

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

确定