【发布时间】:2021-03-06 17:24:34
【问题描述】:
我在 Angular + AngularFire + Firestore 项目中有如下模型
export interface Game {
id: string;
... some other properties
players: Array<{
userId: string;
name: string;
picture: string;
}>;
playerIds: { [userId: string]: boolean };
}
数据看起来像这样
现在我想查询特定 userId 是玩家之一的所有记录。
因为我只想过滤userId(不是整个玩家对象),我不能使用array-contain,所以我添加了一个playerIds属性,它是一个地图对象。
我的代码是这样的
this.collection((ref) => ref.where(`playerIds.${user.id}`, '==', true).where(`status`, '!=', GameStatus.Started)).valueChanges(),
然后它要求我为这个查询创建一个索引。问题是索引对于该用户来说非常具体,并且包含该特定用户 ID。
在我在 nodejs 中使用 firebase 的另一个项目中,我一遍又一遍地做同样的事情,但在 AngularFire 中似乎有所不同。
我知道如果我将其更改为可以通过array-contains 查询的 userId 数组,我的问题是为什么这不起作用以及如何使它起作用。
【问题讨论】:
标签: angular firebase google-cloud-firestore angularfire