GeoFirestore-是否可以在GeoQuery中组合near和where方法?

问题描述

 // Queries
 let query = geoCollection
    .where("status","==","active")
    .near({ center: new firebase.firestore.GeoPoint(latitude,longitude),radius: 1000 });

 // Subscribe,add jobs into store and listen for changes
 query.onSnapshot((res) => res.docs && Array.from(res.docs.map((doc) => console.log(doc.data()))));

执行上述操作时,它无法正常工作。 但是,如果我这样做,它将起作用:

 let query = geoCollection.where("status","active")

let query = geoCollection.near({ center: new firebase.firestore.GeoPoint(latitude,radius: 1000 });

但不能在一起!这就是我想要的。

这是文档的链接。它不是很详细,但是我尽力调查了文件,到目前为止还没有运气。 https://firebaseopensource.com/projects/geofirestore/geofirestore-js/

这是结构的图片

enter image description here

解决方法

最后找到了解决方案。要求您在Cloud Firestore控制台中创建索引。

  1. 在我的案例中,您将集合名称放在第一个字段中是“工作”
  2. 将要比较的“ where”属性放在字段中(升序)
  3. 最后,键入g.geohash(升序)
  4. 单击“保存”,然后等待5至10分钟。

enter image description here