【问题标题】:How to actually query data from Firestore with GeoFirestore?如何使用 GeoFirestore 从 Firestore 实际查询数据?
【发布时间】:2018-12-19 21:03:25
【问题描述】:

我正在尝试在我的 node.js 项目中使用 GeoFirestore 来查询 Firestore 中给定半径内给定点附近的文档。首先,我在数据库中有一个这种格式的文档:

我的查询代码是这样的:

// Create the GeoFirestoreQuery object
const geoQuery = geoFirestore.query({
    center: new firebase.firestore.GeoPoint(latitute, longitude),
    radius: 5,
    query: (ref) => ref.where("d.available", "==", true)
});

问题是,我无法弄清楚如何从查询中获取文档。我尝试了下面的代码,但根本没有调用它。

// Fetch the nearest couriers
const onKeyEnteredRegistiration = geoQuery.on("key_entered", function(key, document, distance) {
    console.log(key);
});

如何退回文件?我错过了什么?我的查询和数据库结构匹配吗?是否缺少任何字段或问题?或者我应该使用另一个查询而不是“key_entered”?感谢您提前提供任何帮助。

【问题讨论】:

  • 我认为问题出在数据结构上。我应该使用名为“d”的地图来存储所有字段吗?我应该在字段“g”中存储地理点或地理哈希字符串吗?我很困惑。

标签: node.js google-cloud-firestore geofirestore


【解决方案1】:

我发现了问题,它与数据库结构有关。我改变了我的结构,如下所示,现在它完美地工作了。

【讨论】:

  • 在您进行查询后,您能否在快照中获取其他字段,例如 namephone 等?我只能看到文件id :S
  • 你发现了吗?除了 id 之外,我也无法得到任何东西
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多