How to switch from Datastore to Firestore in existing project?

半城伤御伤魂 提交于 2021-02-11 09:08:31

问题


I have an existing Google Cloud project which uses Datastore. I'm excited by Firestore and would like to switch. According to https://www.youtube.com/watch?v=SYG-BgXoJFQ it is recommended to create a new project.

Is it possible to just nuke Datastore somehow (I don't care about the data) and start from scratch with Firestore?

If not, what are the implications of creating a new project?


回答1:


It is not possible to switch from Datastore to Firestore within the same project as yet, but you may operate Firestore in Datastore mode. By creating a Cloud Firestore database in Datastore mode, you can access Cloud Firestore's improved storage layer while keeping Cloud Datastore system behavior. You may find more information of relevance by reading the "Automatic Upgrade to Cloud Firestore" documentation page.




回答2:


If there is no data written to Cloud datastore, it's possible to convert from datastore to firestore with the following steps. I tried on 2 projects and each project took 3 minutes. The user should be the project owner to attempt:

  1. Disable Cloud datastore API
  2. Disable Cloud Firestore API
  3. gcloud firestore databases create --region=us-central --project $PROJECT_ID

I have another project that has little datastore entities. I deleted them and executed the steps, but received the following error. While disabling datastore API, I read 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.

ERROR: (gcloud.firestore.databases.create) Error Response: [9] The "database_type" field cannot be modified for this application. Note: If data has already been written for this application, then the "database_type" may not be modified.

The solution is to contact Google cloud support to convert from Datastore to Firestore. You need to make sure no entities exist and nothing is creating any entities.

In the case where no Datastore entities have been written, the operation should succeed:

Success! Selected Google Cloud Firestore Native database for $PROJECT_ID



来源:https://stackoverflow.com/questions/52434455/how-to-switch-from-datastore-to-firestore-in-existing-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!