【发布时间】:2019-08-09 10:55:46
【问题描述】:
我在 firebase 中有以下文档结构:
{
typeId: number,
tripId: number,
locationId: string,
expenseId: number,
createtAt: timestamp
}
我想每次都使用不同的“where”语句来查询这个集合。有时用户希望按类型 id 过滤,有时按 locationId 过滤,或者可能包括所有过滤器。
但似乎我需要为每个可能的排列创建一个复合索引?例如:typeId + expenseId, typeId + locationId, location + expenseId,等,否则不起作用。
如果我有 20 个字段并且我希望能够搜索所有这些字段,该怎么办?
您能否帮我构建一个查询和索引以满足以下要求:查询所有字段的可能性,查询可以包含一个、两个、三个、全部或不包含在 where 子句中的字段,并且始终必须按降序排序通过 createdAt 订购。
【问题讨论】:
-
你需要添加所有的索引
-
这种情况下,firebase 没用!怎么会有人用?
-
@WildGoat 如果您不需要订单,您可以使用任何可能的排列,而无需创建索引。
-
谢谢,但我需要 createdAt 的订单:(
标签: firebase google-cloud-firestore