GCP Firestore API is not available for Cloud Datastore projects
Asked Answered
S

5

14

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 ?

Stereography answered 18/9, 2019 at 23:34 Comment(0)
P
10

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

Pliocene answered 19/9, 2019 at 2:31 Comment(5)
I am not trying to upgrade it. I do have non-empty Cloud datastore db. I tried to delete all the entities and disabled the datastore api, and it still won't allow me to use firestore api. I actually just want to throw the data away there (POC data) and try to use firestore, seems like I was locked out because I used datastore before.Stereography
So can you recommend what I should do here in order to use firestore ?Stereography
Currently there is nothing you could do to upgrade your Datastore database to Firestore in your existing project but to wait for the automatic upgrade from GCP. Since the mode you picked is locked in for the project.Pliocene
Thanks, appreciate your response.Stereography
Are there any ways to do this automatically via command line?Simonetta
N
7

I had The Cloud Firestore API is not available for Datastore Mode projects with an empty Firestore.

I've solved the error with the steps:

  1. Open Firestore in your web browser.
  2. Create at least one collection.

Sadly, Google error messages are useless, as you see by this example.

Neutralize answered 27/12, 2021 at 13:5 Comment(1)
This was it for me. After converting from Datastore Mode it was still recognized as such until I created a document from the web dashboard.Ragout
U
1

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);
Undergarment answered 13/7, 2020 at 4:51 Comment(0)
M
0

Ok, this is my resolution:

  1. Open Google Cloud Console Database: https://console.cloud.google.com/datastore/databases
  2. Select Database that you are using, in my case is "(default)" database enter image description here
  3. Click on (default) -> you will see button 'Switch to Native Mode' -> click on it, done! enter image description here
Maroon answered 18/9, 2019 at 23:34 Comment(0)
D
0

Well, You are most probably using firestore in datastore mode, so, you need to go and change it to native mode, in order to make changes from the terminal. just switch to native mode and it should work fine.

Draughty answered 7/6, 2023 at 1:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.