簡體   English   中英

Cloud Firestore 觸發器不適用於 Cloud function

[英]Cloud Firestore trigger not working for Cloud function

我正在嘗試使用 Cloud Firestore 觸發器調用 Cloud Function。 基本上,只要將新文檔添加到“評論”,我的雲 function 就會完全導出我的子集合“評論”。 我的“評論”子集合中有大約 6-7 個文檔。 我通過控制台部署了function,部署完成。 但是,每當我將新文檔添加到“評論”子集合時,都不會觸發此 function。 有人可以告訴我可能是什么問題嗎?

觸發器類型: Cloud Firestore (Beta)事件類型: providers/cloud.firestore/eventTypes/document.write文檔路徑: test_restaurant/{reviews}

在此處輸入圖像描述

編輯:我希望我的雲 function 僅將添加到我的 Firestore 的新文檔導出到我的 GCP 存儲桶。 下面是我要寫的 function:

const functions = require('firebase-functions');
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();

const bucket = 'gs://ABC/trigger_test'
exports.newFirestoreBackup = functions.firestore
  .document('test_restaurant/{Id}/reviews/{Id}') 
  .onWrite((change, context) => {
   const databaseName = client.databasePath(
   // process.env.GCLOUD_PROJECT,
   "FS-123",
    '(default)'
  );
return client
    .exportDocuments({
      name: databaseName,
      outputUriPrefix: bucket,
      // Leave collectionIds empty to export all collections
      // or define a list of collection IDs:
      // collectionIds: ['users', 'posts']
      collectionIds: ['reviews'],
    })
    .then(responses => {
      const response = responses[0];
      console.log(`Operation Name: ${response['name']}`);
      return response;
    })
    .catch(err => {
      console.error(err);
    });
  
  
  });

控制台片段: 在此處輸入圖像描述

您不共享任何代碼,但如果您希望“每當 [您] 向reviews子集合添加新文檔時”觸發 Cloud Function,則應使用以下路徑聲明:

exports.createUser = functions.firestore
    .document('test_restaurant/{restaurantId}/reviews/{reviewId}')
    .onCreate((snap, context) => {...});

您也可以使用具有相同路徑的onWrite()觸發器。

暫無
暫無

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

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