如何在Firestore上查询字段中包含字典数组的位置?
我正在尝试从firestore
中获取项目数据,这是我在firestore上的结构:
,这是我的代码:
FirestoreReferenceManager.rootProjects.whereField(
FirebaseKeys.ProjectDetails.inviteData,
arrayContains: [
FirebaseKeys.ProjectDetails.otherUserId: userID,
FirebaseKeys.ProjectDetails.inviteStatus: FirebaseKeys.ProjectDetails.pending
])
如果我没有isinvoiceAceCaccess firestore上的数据然后上面的代码工作正常,但是当我在firestore上添加该密钥时,请查询没有给我任何结果,我无法添加该密钥,因为它可以是
true
或false
。
如果我使用以下代码,那么我将获得结果:
FirestoreReferenceManager.rootProjects.whereField(
FirebaseKeys.ProjectDetails.inviteData,
arrayContains: [
FirebaseKeys.ProjectDetails.otherUserId: userID,
FirebaseKeys.ProjectDetails.inviteStatus: FirebaseKeys.ProjectDetails.pending,
FirebaseKeys.ProjectDetails.invoiceAccess: true
])
因此,我需要从firestore
中的数据,而无需在我的查询中添加isinvoiceaccess
。
I am trying to fetch project data from FireStore
and here is my structure on firestore:
And here is my code:
FirestoreReferenceManager.rootProjects.whereField(
FirebaseKeys.ProjectDetails.inviteData,
arrayContains: [
FirebaseKeys.ProjectDetails.otherUserId: userID,
FirebaseKeys.ProjectDetails.inviteStatus: FirebaseKeys.ProjectDetails.pending
])
If I don't have isInvoiceAccess
data on firestore then above code is working fine but when I add that key on firestore then above query is not giving me any results and I can not add that key because it can be true
or false
.
If I use below code then I am getting the results:
FirestoreReferenceManager.rootProjects.whereField(
FirebaseKeys.ProjectDetails.inviteData,
arrayContains: [
FirebaseKeys.ProjectDetails.otherUserId: userID,
FirebaseKeys.ProjectDetails.inviteStatus: FirebaseKeys.ProjectDetails.pending,
FirebaseKeys.ProjectDetails.invoiceAccess: true
])
So I want data from FireStore
without adding isInvoiceAccess
in my query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ArrayContains
操作仅检查数组中是否有确切的匹配,它无法检查部分匹配项。用例的常见解决方法是为要查询的每个特定值/组合添加一个附加的数组字段。因此,在您的情况下,添加一个字段
Invites_UID_AND_STATUS
只有每个两个值,然后在此查询中使用 。The
arrayContains
operation only checks whether there is exact match in the array, it cannot check for partial matches.The common workaround for your use-case is to add an additional array field for each specific values/combination of values that you want to query on. So in your case, add a field
invites_uid_and_status
with just those two values for each, and then use that for this query.