'Cannot switch Firestore from Datastore to native mode on GCP

Somehow the Firestore initialized with the Datastore mode and I can't switch it back to the Firestore native mode even the Datastore is empty.

There's no useful info I can get from the error message.

failed in switching firestore mode



Solution 1:[1]

After the first write, you cannot change the mode once it has been created.

You cannot disable, re-enable and recreate a Firestore database in the same Project either. This is unfortunate and is likely an historical consequence of Datastore's original relationship with App Engine.

The only possibly way this could be change (after the first write) is with help from the magical elves in Google Support but, I'm confident that they're not able to do this either.

There are no magical elves that create these resources though, someone who has permissions on your Project created the Firestore database in Datastore mode.

Solution 2:[2]

The answer is here in the "Choosing between Native and Datastore" mode section

If your database is empty, you can change between Native mode and Datastore mode.

You can accomplish this using a patch request, assuming you've also obtained the valid credentials. For example:

curl --request PATCH \
--header "Authorization: Bearer "$(gcloud auth print-access-token) \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"type":"DATASTORE_MODE"}' \
"https://firestore.googleapis.com/v1/projects/PROJECT_ID/databases/(default)?updateMask=type"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DazWilkin
Solution 2 democrenes