【问题标题】:Listening to documents in a timed Firebase function在定时 Firebase 函数中收听文档
【发布时间】:2022-10-05 23:20:31
【问题描述】:

我创建了一个 node.js 函数,可以在我的 firestore 数据库中查找文档,并且它可以成功运行,但我正在使用 .get() 查询它

有什么方法可以触发一个功能,该功能将等待完成,直到找到文档(因为文档是由不同的应用程序上传的)并设置在计时器上,这样如果计时器用完并且没有找到文档(比如说5 分钟)它会返回一个空文档值吗?

我当前的功能现在看起来像这样:

export const createFinder = async (latitude, longitude, orderUid) => {

    // Find cities within 5km of location
    
    const radiusInM = 50 * 100;

    const bounds = geofire.geohashQueryBounds([latitude, longitude], radiusInM);
    const promises = [];
    
    for (const b of bounds) {
    const q = db.collection(\'availableDocuments\')
        .orderBy(\'geohash\')
        .startAt(b[0])
        .endAt(b[1]);

        const snapshot = await q.get();
        promises.push(snapshot);
    }

    return promises;

}

    标签: node.js firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    看来您正在寻找Firestore triggered Cloud Functions。您可以使用onCreate(),它会在每次添加文档时触发一个函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多