我希望限制GeoFirestore结果的结果,类似于Firestore中的功能。我尝试以各种方式在查询中使用limit(),但是收到了一个无限制函数的错误。这不可能吗?
const geoFirestore = new GeoFirestore(firebase.firestore());
const geoCollectionRef = geoFirestore.collection('locations');
const query = geoCollectionRef.near({
center: new firebase.firestore.GeoPoint(39.76068, -104.98471),
radius: 10
});
query.get().then((value = GeoQuerySnapshot) => {
value.docs.forEach(doc => {
console.log(doc)
})
})发布于 2019-01-11 23:14:57
因此,这些附加函数的问题是,当您执行Geoquery时,为了使查询能够工作,我们聚合了多个查询。
我们创建一个包含地理哈希的查询数组,这些查询围绕您选择的区域。因此,我们可以将限制应用于每个查询,但当聚合时,每个查询都会有限制应用到它,并且聚合将更大。因此,在客户端,我必须重新应用这个限制。这是非常可行的,它不是很有效率。
到目前为止,它是不支持的,但我正在寻找应用的道路上。你能做的一件事是.
import * as firebase from 'firebase';
import { GeoQuery, GeoQuerySnapshot } from 'geofirestore';
const collection = firebase.firestore().collection('somecollection');
// APPLY LIMIT HERE
const limitQuery = collection.limit(50);
const query = new GeoQuery(limitQuery).near({
center: new firebase.firestore.GeoPoint(39.76068, -104.98471),
radius: 10
});
query.get().then((value: GeoQuerySnapshot) => {
value.docs.forEach(doc => {
console.log(doc);
});
});但是,在这种情况下,geoquery的每个查询都有应用的限制,而不是聚合。您可以修改您想要的限制号,以便在客户端得到更接近的信息。(您将在2月份的某个时候看到这个特性的正确集成)
https://stackoverflow.com/questions/54150085
复制相似问题