首页 > 解决方案 > 使用调度程序 Firebase 云功能检索 IP 地址并存储在 Firestore 中

问题描述

每 30 分钟 Cloud Function 应调用一次(google schedulerCloud Function triggers) 在触发器中,节点代码检索 IP 地址并将其保存在 firestore(firebase)中 每次检索时,它都应存储在 firestore 的当前 IP 字段中。每次都要比较IP。如果 IP 地址相同,则什么也不做。如果 Ip 更改更新当前 ip 并将旧 ip 保存在以前的 IP 中,并列出数组以使用 nodejs 使用 firebase 云功能存储所有新 IP 我当前的代码 index.js 文件

        exports.scheduledFunction = functions.pubsub.schedule('every 1 minutes').onRun((context) => {
       db.collection("getIpAddress").doc("LA").set({
       currIp:request.ip,
        prevIp: ""
        })
      .then(() => {
       console.log("Document successfully written!");
       })
       .catch((error) => {
       console.error("Error writing document: ", error);
       });
       console.log('This will be run every 5 minutes!');
       return null;
        });

 

在这段代码中,我收到 request is undefined 错误。

标签: javascriptnode.jsfirebaseexpressgoogle-cloud-firestore

解决方案


推荐阅读