这似乎是一个非常简单的问题,我想我只是盯着它太久了。我正在尝试查询数据库上的交易历史记录,但我只希望用户能够阅读他们所涉及的交易文档。我知道查询约束必须匹配规则约束,而我的似乎。有人可以在这里找到问题所在吗?
Firebase规则
match /transaction-history/{transactionId}{
allow read: if isPurchaserOrReciever(getTransaction(transactionId));
}
function isPurchaserOrReciever(transaction) {
return transaction.purchaserId == request.auth.uid || transaction.recieverId == request.auth.uid;
}
function getTransaction(transactionId) {
return get(/databases/$(database)/documents/transaction-history/$(transactionId)).data;
}
我的应用程序中的数据库查询。
await firestore
.collection('transaction-history')
.where('purchaserId', isEqualTo: myId)
.getDocuments()).documents;
答案 0 :(得分:0)
我仍然不确定为什么以前的查询无法正常工作。在进行更多研究时,我发现了一种简化查询的方法,并且不会引发任何错误。如果有人可以告诉我以前的规则或查询出了什么问题,我仍然很感兴趣。
match /purchase-logs/{purchaseId}{
allow read: if resource.data.userId == request.auth.uid;
}
match /transaction-history/{transactionId}{
allow read: if resource.data.purchaserId == request.auth.uid || resource.data.recieverId == request.auth.uid;
}