typescript - geofirestore 不返回单个文档数据
问题描述
我们正在使用geofirestore npm 包来获取附近的文档。
这是我们用来获取这些文档的云函数。
exports.getNearbyOffers = functions.https.onCall((data, context) => {
const offers = GeoFirestore.collection('restaurants');
const center : GeoPoint = new admin.firestore.GeoPoint(data["sourceLat"], data["sourceLng"]);
const query = offers.near({center: center, radius: 100,});
return query.get().then((value) => {
console.log(value.docs);
return value.docs;
}).catch((err: any) => {
console.log(err);
});
});
客户端的输出是:
[{data: {}, distance: 0, exists: true, id: LdaLz30gv16Gv68Xw92i}, {data: {}, distance: 0, exists: true, id: Ux1Et5afklvZC4IKEkJy}, {data: {}, distance: 0, exists: true, id: h4kdFZpsn1UwPpTvPMxC}, {data: {}, distance: 0, exists: true, id: oqWfc41cfiWAcnvufVFd}, {data: {}, distance: 0, exists: true, id: pH0qW0V9rY43zvgkPQm8}]
查询返回正确的文档 ID。但是,这些文档的数据是空的,但是,在 Firestore 控制台中,每个对应的文档都有许多带有数据的字段(名称、评级、地址等)。
解决方案
这是意料之中的,因为您只获得快照。您需要在每个文档上运行 data() 函数以获取其数据:
query.get().then((value) => {
// All GeoDocument returned by GeoQuery, like the GeoDocument added above
for (const doc of value.docs) {
console.log(doc.data());
}
推荐阅读
- elasticsearch - Elastic-Cloud 未从 Serilog Sink 接收数据
- android - 我想每隔三个位置在列表视图中添加 google admob 原生广告,但我不能
- linux - linux中的简单排序
- postgresql - PostgreSQL 使用 JSONB 和 TypeORM 加入
- java - 一段时间后如何启动代码?
- php - prestashop 网址到类别
- docker - 在 devcontainers 中配置对私有存储库的访问
- scala - spark检测并提取列值中的模式
- swift - XCode + Swift:线程 1:EXC_BAD_ACCESS(代码=2,地址=0x7ffee99cdfd8)
- c# - C# http-get url JSON 数据并将其解析为文本..?