【问题标题】:Exporting data from Firestore to GCS将数据从 Firestore 导出到 GCS
【发布时间】:2021-12-24 12:22:14
【问题描述】:

我试图使用此代码 sn-p 将数据从 firestore 导出到谷歌云存储

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

const bucket = 'gs://BUCKET_NAME';

exports.scheduledFirestoreExport = functions.pubsub.schedule('every 24 hours').onRun(async() => {

  const projectId = process.env.GCP_PROJECT || process.env.GCLOUD_PROJECT;
  const databaseName = client.databasePath(projectId, '(default)');

  const response = await client.exportDocuments({
        name: databaseName,
        outputUriPrefix: bucket,
        collectionIds: [],
      });
 console.log(`Backup Successful :${response}`, {response});
//here I am trying to import the data to bigquery
});

我面临的问题是 client.exportDocuments 在 Google Cloud Storage Bucket 中创建文件之前几毫秒完成。因此,当我尝试访问它进行导入时,它说不存在这样的文件。URL 错误。

对此有何建议?

【问题讨论】:

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


    【解决方案1】:

    这是底层方法 databases.export documents.

    response 是一个 Operation,它可能是 GCP 上长期运行的进程。

    您需要轮询(我认为无法订阅)操作端点,直到作业成功或失败。

    如果完成,您就可以开始 BigQuery 作业了。

    见:Managing Export and Import operations

    但是,这可能会超过 Cloud Function 的超时时间,并且可能不应在单个函数调用期间尝试。

    您可能需要考虑创建另一个在导出完成后触发的进程。我没有这样做。您可以创建一个由 GCS 事件触发的后台函数。我不知道。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-17
      • 2015-04-04
      • 2015-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 2018-04-30
      相关资源
      最近更新 更多