We're trying to run a script on could-shell to create a new firestore collection in native mode.
However it creates it in datastore default mode.
What should be change in our flags? --type=firestore-native
Code:
create_firestore() {
DB_EXISTS=$(gcloud firestore databases list --filter="name=projects/'$PROJECT_ID'/databases/'$DB_NAME'" --format="get(name)")
if [[ ! -n $DB_EXISTS ]]; then
echo -e "\n${COLOR}Creating Firestore...${NC}"
gcloud firestore databases create \
--database=$DB_NAME \
--location=$DB_REGION \
--type=firestore-native
else
echo -e "\n${COLOR}Firestore exists.${NC}"
fi
}
I saw we can switch modes when the DB is empty. And this also shows we're using the right flag then.
As I have mentioned above when I have tried gcloud firestore databases create --location=us-east1 --type=firestore-native
database created in native mode only.
And also I have tried to replicate the issue using your script by hardcoding the project and DB values as shown below. This time as well I am able to create the database in native mode without any issues.
#!/bin/sh
create_firestore() {
DB_EXISTS=$(gcloud firestore databases list --filter="name=projects/xxx-dexx-xxx/databases/testdb" --format="get(name)")
if [[ ! -n $DB_EXISTS ]]; then
echo -e "\n${COLOR}Creating Firestore...${NC}"
gcloud firestore databases create \
--database=testdb \
--location=us-central1 \
--type=firestore-native
else
echo -e "\n${COLOR}Firestore exists.${NC}"
fi
}
create_firestore
You may refer to below screenshot for the output after execution of the script.
As you have not shared your complete script, I believe that there might be an issue in some other part of your script. I suggest you verify your complete script.
Note: gcloud command will create a database in firestore mode by default. So there is no need to use --type
flag explicitly