【问题标题】:How to export firestore data collection by collection field value如何按集合字段值导出 Firestore 数据集合
【发布时间】:2020-06-08 07:56:43
【问题描述】:

我正在尝试使用以下命令将 google firestore 数据导出到云存储位置。

    gcloud firestore export gs://<bucketName>/<folderName> --collection-ids=<collectionName>

我想进一步按字段名称值或日期范围过滤集合,可以这样做吗?云功能解决方案也欢迎。

这是我的 js 解决方案

  console.log('data export bucket', bucket);

  const databaseName = client.databasePath(
    process.env.GCLOUD_PROJECT,
    'project_name'
  );

  const response = await client
    .exportDocuments({
      name: databaseName,
      outputUriPrefix: bucket,
      // Leave collectionIds empty to export all collections
      // or define a list of collection IDs:
      // collectionIds: ['users', 'posts']
      collectionIds: tables,
    });
  console.log('successfully exportToGCS', response);

}```

【问题讨论】:

    标签: google-cloud-platform collections google-cloud-firestore export google-cloud-storage


    【解决方案1】:

    在撰写本文时,Firestore 导出功能中不存在这种可能性。我想到了这些选项:

    1) 由于exports and imports are charged at the same rate as read/write operations,我建议在 FS 中运行查询而不是使用导出功能。您可以按照您已经提出的建议使用常规 Cloud Function 运行这样的查询。参考this guide for getting multiple documents from a collection

    2) 如果您确实需要 Firestore/Datastore 导出格式,可以选择将所有过滤后的数据复制到新集合并从那里导出,但您可能会支付比您想要的更多的费用。

    根据您接下来要对数据执行的操作,您可以创建一个云函数来侦听更改并将过滤后的数据复制到一个新集合中,然后您可以从中导出。

    【讨论】:

      猜你喜欢
      • 2019-09-26
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 2019-06-05
      • 2021-11-04
      • 2021-04-21
      • 1970-01-01
      • 2022-07-31
      相关资源
      最近更新 更多