GCP Firestore API is not available for Cloud Datastore projects

我的梦境 提交于 2021-02-05 05:40:20

问题


I was trying to use the GCP filestore, following the simple quick example in the product website and get an error: "google.api_core.exceptions.FailedPrecondition: 400 The Cloud Firestore API is not available for Cloud Datastore projects."

I did use the datastore before in the same project, I then disabled the datastore api in the project and try out the example, still get the same error any one can suggest what to do other than creating a new project ?


回答1:


If you have an empty Cloud Datastore database and you never executed a write to the database, you can upgrade to Cloud Firestore in Datastore mode or Native mode, by clicking the ‘’UPGRADE TO FIRESTORE’ button on the ‘Datastore/Entities’ page.

If you do not receive the option, then your database instance will be automatically upgraded at a future date(link). If you upgrade from Cloud Datastore to Cloud Firestore in Datastore mode or from Datastore mode to Native mode, you cannot undo the operation.

Here is the link to the Doc: https://cloud.google.com/datastore/docs/upgrade-to-firestore




回答2:


I had the same problem, the solution was to comment the line .setProjectId(projectId).

this example is for a native firestore instance, located in another GCP project

GoogleCredentials credentials = GoogleCredentials.fromStream(new ClassPathResource("/test-firebase.json").getInputStream());

FirebaseOptions options = new FirebaseOptions.Builder()
    .setCredentials(credentials)
    //.setProjectId(projectId)
    .setDatabaseUrl("https://document-db.firebaseio.com/")
    .build();

if (FirebaseApp.getApps().isEmpty()) {
  FirebaseApp.initializeApp(options);
}

Firestore db = FirestoreClient.getFirestore();
DocumentReference docRef = db.collection("document-db").document("alovelace");
// Add document data with id "alovelace" using a hashmap
Map<String, Object> data = new HashMap<>();
data.put("first", "Ada");
data.put("last", "Lovelace");
data.put("born", 1815);
// asynchronously write data
ApiFuture<WriteResult> result = docRef.set(data);


来源:https://stackoverflow.com/questions/58001922/gcp-firestore-api-is-not-available-for-cloud-datastore-projects

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