簡體   English   中英

Firebase Function 執行耗時 2794 毫秒,完成狀態為:“確定”,...但 Firestore 中沒有發生任何變化

[英]Firebase Function execution took 2794 ms, finished with status: 'ok' ,... but no change took place in Firestore

我正在嘗試使用 Cloud Functions 和 NodeJs 更新 Firestore 中嵌套子集合中的所有文檔。

collection().doc().collection.doc().collection().doc()

/timeline/105358539742688769892/publisherId/105358539742688769892/posts/29b975f2-0d53-4e06-8365-3d5442355a78 在此處輸入圖像描述

這是我的代碼。

exports.onCreateTimelineTest = functions.firestore
  .document("/timelineTest/{docId}")
  .onCreate(async (snapshot, context) => {

const timeNow =new Date();
const db = admin.firestore();
    return db.collection("timeline")
    .get()
    .then((timelineQuerySnapshot) => {
     timelineQuerySnapshot.forEach(async(timelineQuerySnapshot) => {


      console.log("all the documnets inside timeline are", timelineQuerySnapshot.id);

       await db.collection("timeline")
        .doc(timelineQuerySnapshot.id)
        .collection("publisherId")
        .get()
        .then((publisherSnapshot)=>{
    publisherSnapshot.forEach(async(publisherSnapshot)=>{


      console.log("all the documnets inside timeline are", publisherSnapshot.id);

    await db.collection("timeline")
     .doc(timelineQuerySnapshot.id)
     .collection("publisherId")
     .doc(publisherSnapshot.id)
     .collection("posts")
     .where('uploadTime', '<=', timeNow)
     .get()
     .then((postSnap)=>{
    postSnap.forEach(async(postSnap)=>{


    console.log("all the documnets inside timeline are", postSnap.id);

    return db.collection("timeline")
    .doc(timelineQuerySnapshot.id)
    .collection("publisherId")
    .doc(publisherSnapshot.id)
    .collection("posts")
    .doc(postSnap.id)
    .set({
    'name': 'madhav'
                         }).catch((err)=>{
                         console.log('Error getting documents', err);
                         return Promise.reject(err);
                         });
                      });
        return null
        }).catch((err) => {
                   console.log('Error getting documents', err);
                   return Promise.reject(err);
                  });
        });
        return null
        }).catch((err) => {
         console.log('Error getting documents', err);
         return Promise.reject(err);
        });
    });
    return null
    }).catch((err) => {
     console.log('Error getting documents', err);
     return Promise.reject(err);
    });

  });

這些功能在模擬器中運行良好,部署后,狀態為“ok”。 但是當我檢查 firestore 時,我發現沒有發生任何變化。 它仍然是一樣的。

在此處輸入圖像描述

花了 2 天時間后,我找到了解決方案,而且非常愚蠢。

在屏幕截圖中,它說,

該文檔不存在,它不會出現在查詢和快照中。

因此,我必須向每個文檔添加一個字段,然后函數才能正常工作。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM