【发布时间】:2019-04-08 04:41:16
【问题描述】:
我想创建一个动态构造查询的查询函数 - 但是我似乎可以让任何查询元素绑定到查询:
在这里,我创建了 observable,我将 ref 传递给查询构建函数,该函数添加了我需要搜索的所有内容:
firebaseObservable = this.firestoreService.colWithIds$('bucket', ref => this.createFirebaseQuery(ref, this.filterParams.filterBy, pagination));
我在这里构造查询
createFirebaseQuery(ref: any, categories: string[], isPagination?: boolean) {
// Fetch the requests order by direction
const direction: OrderByDirection = this.filterParams.sortBy.direction === 'asc' ? 'asc' : 'desc';
// Add th category search criteria
for (const category of categories) {
ref.where(`categoriesTest.${category}`, '==', 'true');
}
// Order by selected type and direction
ref.orderBy(this.filterParams.sortBy.type, direction);
// Check if the requests skills are new page
if (isPagination) {
ref.startAfter(this.paginationCursor);
}
// Add a limit to the results being returned
ref.limit(20);
return ref;
}
这似乎永远不会对它应用任何 where 子句或限制...?
【问题讨论】:
标签: typescript firebase google-cloud-firestore