我正在尝试查询具有2个字段的集合。我正在使用> =,另一个用于orderBy
我用这2个字段创建了一个复合索引,但出现此错误:
Exception 'Invalid query. You have a where filter with an inequality (lessThan, lessThanOrEqual, greaterThan, or greaterThanOrEqual) on field 'expiresAt' and so you must also use 'expiresAt' as your first queryOrderedBy field, but your first queryOrderedBy is currently on field 'sharedAt' instead.' was thrown while invoking collectionGet on target RNFirebaseFirestore with params (
"[DEFAULT]",
"users/je601IzZ33VZGYg7iNeTEfOgsis1/canvas",
(
{
fieldPath = {
string = expiresAt;
type = string;
};
operator = "GREATER_THAN_OR_EQUAL";
value = {
type = number;
value = 1563621170;
};
}
),
(
{
direction = DESCENDING;
fieldPath = {
string = sharedAt;
type = string;
};
}
),
{
},
"<null>",
198,
199
)
我的查询:
firestore().collection(`users/[id]/canvas`)
.where('expiresAt', '>=', Math.floor(Date.now() / 1000))
.orderBy('sharedAt', 'desc')
所以,这告诉我我需要具有expiresAt作为第一订单。所以:
firestore().collection(`users/[id]/canvas`)
.where('expiresAt', '>=', Math.floor(Date.now() / 1000))
.orderBy('expiresAt', 'desc')
.orderBy('sharedAt', 'desc')
这样做时,我收到错误消息,指出系统未处于执行查询的正确状态。
我尝试了不同的组合以使其正常工作。
一些信息:expiresAt是集合中的项目对用户不再可见的时间。 SharedAt是该项目首次添加到用户列表的时间。
edit:模式很简单。用户有一个包含项目的子集合“画布”,这里唯一涉及的字段是时间戳:
title: String,
description: String,
sharedAt: Number,
expiresAt: Number