Firestore multiple orderBy (composite index) 找不到一些结果
Firestore multiple orderBy (composite index) can't find some results
我有一个 运行 对多种数据类型的查询。在我添加 orderBy
s 后,collections 之一停止了 returning 结果。
getEntitiesOfType(entityType: EntityType): Observable<StructuralEntity[]> {
const collection = this.findCollection(entityType);
const entities$ = this.afs
.collection(collection, (ref) =>
ref.orderBy('disabled').orderBy('title').orderBy('id') // Here is the issue
)
.snapshotChanges()
.pipe(
map((docs) =>
docs.map((dca) => {
const data = dca.payload.doc.data() as StructuralEntity;
return {
id: dca.payload.doc.id,
title: data.title,
name: data.name,
type: data.type,
icon: data.icon,
model: data.model,
context: data.context,
disabled: data.disabled,
} as StructuralEntity;
})
)
);
return entities$;
}
我不得不通过 disabled
和 title
订购一些 collection,停止 return 结果的 collection 没有这些字段,所以我想这就是它不再 return 任何东西的原因。我已经将字段 id
添加到复合索引中,它肯定有,希望它能再次工作。它没有。
为什么 Firestore return 这个索引没有任何内容?
disabled
title
id
undefined
undefined
"1"
undefined
undefined
"2"
Firestore 仅包含索引中具有该索引中字段值的文档。
如果文档没有 disabled
字段的值,则它不会存在于复合索引中,因此永远不会从使用该索引的查询中返回。
如果您希望返回此类文档,则必须将新字段添加到具有一些默认值的文档中。
我有一个 运行 对多种数据类型的查询。在我添加 orderBy
s 后,collections 之一停止了 returning 结果。
getEntitiesOfType(entityType: EntityType): Observable<StructuralEntity[]> {
const collection = this.findCollection(entityType);
const entities$ = this.afs
.collection(collection, (ref) =>
ref.orderBy('disabled').orderBy('title').orderBy('id') // Here is the issue
)
.snapshotChanges()
.pipe(
map((docs) =>
docs.map((dca) => {
const data = dca.payload.doc.data() as StructuralEntity;
return {
id: dca.payload.doc.id,
title: data.title,
name: data.name,
type: data.type,
icon: data.icon,
model: data.model,
context: data.context,
disabled: data.disabled,
} as StructuralEntity;
})
)
);
return entities$;
}
我不得不通过 disabled
和 title
订购一些 collection,停止 return 结果的 collection 没有这些字段,所以我想这就是它不再 return 任何东西的原因。我已经将字段 id
添加到复合索引中,它肯定有,希望它能再次工作。它没有。
为什么 Firestore return 这个索引没有任何内容?
disabled | title | id |
---|---|---|
undefined | undefined | "1" |
undefined | undefined | "2" |
Firestore 仅包含索引中具有该索引中字段值的文档。
如果文档没有 disabled
字段的值,则它不会存在于复合索引中,因此永远不会从使用该索引的查询中返回。
如果您希望返回此类文档,则必须将新字段添加到具有一些默认值的文档中。