1

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.

https://screenshot.googleplex.com/3wF42vdkNK6u5uA

2
  • I'm able to create firestore in native mode using command `gcloud firestore databases create --location=us-east1 --type=firestore-native`. Can you check if you are using latest version of `gcloud`?
    – Roopa M
    Commented Jul 8 at 18:10
  • I am looking forward to your feedback to understand whether the provided resolution has helped you in resolving the issue. If not, I am happy to assist further.
    – Roopa M
    Commented Jul 15 at 11:42

1 Answer 1

0

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.

image

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.