简体   繁体   English

geofirestore 不返回单个文档数据

[英]geofirestore not returning individual document data

We are using the geofirestore npm package to get nearby documents.我们正在使用geofirestore npm package来获取附近的文件。

This is the Cloud Function we are using to get these documents.这是我们用来获取这些文档的 Cloud Function。

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);
    });
});

The output on the client-side is:客户端的 output 是:

[{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}]

The query is returning the correct document IDs.查询返回正确的文档 ID。 However, the data of these documents is empty, but, in the Firestore console, each corresponding document has many fields with data (name, rating, address, etc.).但是,这些文档的数据是空的,但是,在 Firestore 控制台中,每个对应的文档都有许多带有数据的字段(名称、评级、地址等)。

That's expected because you are getting only the snapshot.这是意料之中的,因为您只获得快照。 you need to run the data() function on each doc to get their data:您需要在每个文档上运行 data() function 以获取其数据:

query.get().then((value) => {
// All GeoDocument returned by GeoQuery, like the GeoDocument added above
  for (const doc of value.docs) {
    console.log(doc.data());
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM