【发布时间】:2021-12-02 16:03:54
【问题描述】:
我有以下文档的 Firestore 集合:
[
{
start: { geohash: 'u3qchtmpuy2d' },
destination: { geohash: 'u3qcjvxfh9cs' },
timestamp: '28 June 2019 at 20:24:00 UTC+2',
...
}
]
我尝试像这样查询它(它的 Firestore Web SDK)
// 5-characters geohash is 4.89km × 4.89km
const start = 'u3qch';
const destination = 'u3qcj';
const timestamps = {
min: firestore.Timestamp.fromDate(
moment(someDateTime).subtract(10, 'minutes').toDate()
),
max: firestore.Timestamp.fromDate(
moment(someDateTime).add(10, 'minutes').toDate(),
),
};
firestore
.collection('deliveries')
.where('start.geohash', '>=', start)
.where('start.geohash', '<', geohashEnd(start))
.where('destination.geohash', '>=', destination)
.where('destination.geohash', '<', geohashEnd(destination))
.where('timestamp', '>=', timestamps.min)
.where('timestamp', '<', timestamps.max)
.get()
>= 和< 的组合来自Firestore: query documents by startsWith a string,因此是geoHashEnd() 函数(超出此问题的范围)。
导致以下错误:
FirebaseError:无效查询。具有不等式( 或 >=)的所有 where 过滤器必须位于同一字段中。但是您在“start.geohash”和“destination.geohash”上有不等式过滤器
我的问题:一次通过两个 geohash 字符串和一个附加字段查询我的 firestore 集合的最佳方法是什么?
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore