【发布时间】:2018-06-13 09:27:27
【问题描述】:
我在使用 Firestore 时玩得很开心,但我现在开始认为使用这个产品可能不切实际,因为我在尝试查询我的数据时遇到了很多挑战。
最终,我试图通过提供一些过滤条件(价格范围、日期范围、地理范围)从 Firestore 文档中检索地理位置列表。不幸的是,Firestore 还不支持多范围查询,也不支持地理查询。以下是我迄今为止尝试过的一些事情。我正在使用 AngularFire2 来实现:
这行得通
@Effect() loadPostings: Observable<Action> = this.actions
.ofType<LoadPostings>(MapActionTypes.Load_Postings)
.switchMap(
latLngBound => this.firestoreDB.collection<Posting>('postings', ref => ref
.where('duration.min', '>=', 1) // --------> this works
).valueChanges()
.map(postings => new LoadPostingsSuccess(postings))
);
这也有效
@Effect() loadPostings: Observable<Action> = this.actions
.ofType<LoadPostings>(MapActionTypes.Load_Postings)
.switchMap(
latLngBound => this.firestoreDB.collection<Posting>('postings', ref => ref
.where('duration.max', '<=', 5) // ------> this works as well
).valueChanges()
.map(postings => new LoadPostingsSuccess(postings))
);
这不起作用(由于某种原因)
@Effect() loadPostings: Observable<Action> = this.actions
.ofType<LoadPostings>(MapActionTypes.Load_Postings)
.switchMap(
latLngBound => this.firestoreDB.collection<Posting>('postings', ref => ref
.where('duration.min', '>=', 1) // ---> 2 range queries dont work :(
.where('duration.max', '<=', 5)
).valueChanges()
.map(postings => new LoadPostingsSuccess(postings))
);
这些限制并不令人意外,因为文档明确指出无法做到这一点。但这怎么能提供呢?好像我正在尝试做一个非常基本的查询,我错了吗?我该怎么做?我应该放弃这个而只做我自己的后端吗?
【问题讨论】:
标签: typescript firebase-realtime-database angularfire2 google-cloud-firestore