【问题标题】:How to switch from Datastore to Firestore in existing project?如何在现有项目中从 Datastore 切换到 Firestore?
【发布时间】:2018-09-20 23:02:54
【问题描述】:

我有一个使用 Datastore 的现有 Google Cloud 项目。我对 Firestore 很感兴趣,想换掉。根据https://www.youtube.com/watch?v=SYG-BgXoJFQ 建议新建一个项目。

是否有可能只是以某种方式核对 Datastore(我不关心数据)并从头开始使用 Firestore?

如果不是,创建一个新项目有什么影响?

【问题讨论】:

    标签: firebase google-cloud-datastore google-cloud-firestore


    【解决方案1】:

    目前尚无法在同一项目中从 Datastore 切换到 Firestore,但您可以在 Datastore 模式下操作 Firestore。通过在 Datastore 模式下创建 Cloud Firestore 数据库,您可以访问 Cloud Firestore 改进的存储层,同时保持 Cloud Datastore 系统行为。您可以通过阅读“自动升级到 Cloud Firestore”文档page 找到更多相关信息。

    【讨论】:

      【解决方案2】:

      如果没有数据写入 Cloud Datastore,则可以通过以下步骤从 Datastore 转换为 Firestore。我尝试了 2 个项目,每个项目花了 3 分钟。用户应该是要尝试的项目所有者:

      1. 禁用Cloud datastore API
      2. 禁用Cloud Firestore API
      3. gcloud firestore 数据库创建 --region=us-central --project $PROJECT_ID

      我有另一个项目,它的数据存储实体很少。我删除了它们并执行了这些步骤,但收到了以下错误。在禁用数据存储 API 时,我阅读了 Disable Cloud Datastore API? If any resources were created by Cloud Datastore API, they may be deleted soon after Cloud Datastore API is disabled. All code that uses this project's credentials to call Cloud Datastore API will fail.

      错误:(gcloud.firestore.databases.create)错误响应:[9] 无法为此应用程序修改“database_type”字段。笔记: 如果已为此应用程序写入数据,则 “database_type”不可修改。

      解决方案是联系 Google 云支持以从 Datastore 转换为 Firestore。您需要确保不存在任何实体,并且没有创建任何实体。

      在没有写入 Datastore 实体的情况下,操作应该会成功:

      成功!为 $PROJECT_ID 选择的 Google Cloud Firestore 本机数据库

      【讨论】:

      • 我能够成功地更改我正在使用的数据库,即使我已经按照这个过程在数据库上写了一些条目,然后调用谷歌云支持。 console.cloud.google.com/support/phone我必须支付 30 美元才能致电支持。
      • 请注意,在禁用 API 和命令行之间,避免在 GUI 中访问 datastore/firestore,它会撤消您的工作并重新启用旧 API!
      • 我尝试了这个技巧,但在最后一步得到了[13] An internal error occurred 消息。有什么想法吗?
      • 请在内部错误发生期间检查云日志中的相关消息。通常,您无法看到此类错误,但请联系 Google 云支持,尤其是该错误是可重现的。
      • 我试过了,但得到了这个错误“应用引擎区域是 us-central,这与 us-east1 不同。现在 Firestore 区域必须与 App Engine 区域匹配。”我在 us-east1 中需要它。我认为这都是因为多年前我创造了一些资源,但从未使用过它们。当心 GCP 中未记录的单向门和活板门副作用。看来我将不得不创建一个新项目并重新设置所有内容,这大约需要 10,000 美元的工作:-(
      猜你喜欢
      • 2018-03-17
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      • 2020-01-30
      • 2011-10-27
      • 2022-12-29
      • 1970-01-01
      相关资源
      最近更新 更多