![](/img/trans.png)
[英]How to get Firebase server time in seconds while set/update data on firestore objective-c?
[英]Update Firebase Firestore Data After A Certain Amount of Time
我想在創建特定時間后更新我的 firestore 插入的字段。 我搜索了幾種可能性並提出了雲功能。 不幸的是,為了編寫 function,java 腳本對我來說並不那么容易理解。此外,我表示,無論如何,在一段時間后不可能執行代碼。
那么我如何在不編寫大量 js 代碼並為使用 function 付費的情況下處理該問題。也許第二個應用程序只是一個周期性計時器並一次又一次地檢查 DateTime 字段。 (我可以 24/7 全天候運行該應用程序)
多謝你們
您可以創建一個雲 function,它會在創建文檔時觸發。 您可以使用像setTimeout()
這樣的計時器來執行 function 來更改文檔。
請看下面的示例代碼:
function updateDoc(id) {
admin.firestore()
.collection('Orders')
.doc(id)
.update({status: 2})
.then(() => {
console.log("Document ID: "+id+" successfully updated!");
})
.catch((error) => {
console.error("Error updating document: ", error);
});
}
exports.updateField = functions.firestore
.document('/Orders/{id}')
.onCreate((snapshot, context) => {
console.log(context.params.id);
const id = context.params.id;
setTimeout(() => updateDoc(id), 600000);
});
您可能需要檢查Cloud Firestore 觸發器以了解其他觸發器,並檢查setTimeout()
以了解您可以在用例中使用的其他超時選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.