在 Firestore 中操作多个操作。任何破解可能吗?
Operate multiple in operations in Firestore. Any hack possible?
我想根据多个in
条件查询多个字段,如下所示:
db
.collection(firebasePaths.funfuse_verified_users)
.orderBy('uid')
.where('uid', 'not-in', notToIncludeAccounts)
.orderBy('skills')
.where('skills', 'in', skills)
.orderBy('interests')
.where('interests', 'in', interests)
Firestore 限制指出每个查询只允许一个 in
,但我想知道我是否可以通过一些 hacky 方式使这项工作正常进行?我想到的一件事是获取两个结果,然后取它们的交集,但这将意味着我的后端有很多负载。
有没有其他我不知道的方法可以用于这种情况?我想根据技能和兴趣数组过滤数据库。
编辑 1:添加了文档示例
文档示例如下所示:
{
"name": "Shivam",
"online": true,
"bio": "",
"skills": [
"Supply Chain",
"Inventory Management",
"Legal",
"Digital Marketing",
"Web"
],
"interests": [
"Healthcare"
],
"imageLoc": "profile-pics/profile-photo",
"isImageAvailable": true,
"uid": "",
"username": "tttt"
},
预期查询:
db
.collection(firebasePaths.funfuse_verified_users)
.orderBy('uid')
.where('uid', 'not-in', ['1','2'])
.orderBy('skills')
.where('skills', 'in', ["Supply Chain","Inventory Management"])
.orderBy('interests')
.where('interests', 'in', ["Supply Chain","Inventory Management"])
类似这样。
API 中没有任何隐藏内容允许 use-case,因此任何解决方法都必须来自对数据模型的更改。
我能想到的最好的办法是添加一个额外的字段来组合 skills
和 interests
值,然后对其进行过滤。
如果您只添加所有单个值 ("skills_and_interests": ["供应链"、"库存管理"、"法律"、"数字营销"、"网络"、"医疗保健"] ),您可以使用 in
对其执行等效的 OR 运算。如果你想区分技能和兴趣,你可以在值前面加上前缀 ("skill_Supply Chain"
, "interest_Healthcare"
).
如果你想过滤组合值,你必须添加技能和兴趣的组合(例如"Supply Chain_Healthcare", "Inventory Management_Healthcare"
),这样你就可以做一个AND like操作。
我想根据多个in
条件查询多个字段,如下所示:
db
.collection(firebasePaths.funfuse_verified_users)
.orderBy('uid')
.where('uid', 'not-in', notToIncludeAccounts)
.orderBy('skills')
.where('skills', 'in', skills)
.orderBy('interests')
.where('interests', 'in', interests)
Firestore 限制指出每个查询只允许一个 in
,但我想知道我是否可以通过一些 hacky 方式使这项工作正常进行?我想到的一件事是获取两个结果,然后取它们的交集,但这将意味着我的后端有很多负载。
有没有其他我不知道的方法可以用于这种情况?我想根据技能和兴趣数组过滤数据库。
编辑 1:添加了文档示例 文档示例如下所示:
{
"name": "Shivam",
"online": true,
"bio": "",
"skills": [
"Supply Chain",
"Inventory Management",
"Legal",
"Digital Marketing",
"Web"
],
"interests": [
"Healthcare"
],
"imageLoc": "profile-pics/profile-photo",
"isImageAvailable": true,
"uid": "",
"username": "tttt"
},
预期查询:
db
.collection(firebasePaths.funfuse_verified_users)
.orderBy('uid')
.where('uid', 'not-in', ['1','2'])
.orderBy('skills')
.where('skills', 'in', ["Supply Chain","Inventory Management"])
.orderBy('interests')
.where('interests', 'in', ["Supply Chain","Inventory Management"])
类似这样。
API 中没有任何隐藏内容允许 use-case,因此任何解决方法都必须来自对数据模型的更改。
我能想到的最好的办法是添加一个额外的字段来组合 skills
和 interests
值,然后对其进行过滤。
如果您只添加所有单个值 ("skills_and_interests": ["供应链"、"库存管理"、"法律"、"数字营销"、"网络"、"医疗保健"] ),您可以使用 in
对其执行等效的 OR 运算。如果你想区分技能和兴趣,你可以在值前面加上前缀 ("skill_Supply Chain"
, "interest_Healthcare"
).
如果你想过滤组合值,你必须添加技能和兴趣的组合(例如"Supply Chain_Healthcare", "Inventory Management_Healthcare"
),这样你就可以做一个AND like操作。